writing serializable objects in a file,but can readObject only one ,and it gives java.io.StreamCorruptedException Type code Outof range is -84
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   sumit_sharma
Posted On:   Wednesday, May 2, 2001 04:53 AM

I have serializable objects which I write in an filein append mode. class is class MyMessage implements Serializable { String to,from; String mess,subject; Date sdate; MyMessage(Message m){ Address t[],fr[]; try{ to = " TO: "; from = " From : "; fr = m.getFrom(); t = m.getRecipients(Message.RecipientType.TO); if (fr != null) for (int i = 0; i < fr.length; i++) { from += fr[i] + " , "; } if (t != null) for (int i = 0; i < t.length; i++) { to +=t[i] + " , "; } subject = m.getSubject(); sdate = m.getSentDate(); Object   More>>

I have serializable objects which I write in an filein append mode.
class is

class MyMessage implements Serializable {
String to,from;
String mess,subject;
Date sdate;

MyMessage(Message m){
Address t[],fr[];
try{
to = "
TO: ";
from = "
From : ";
fr = m.getFrom();
t = m.getRecipients(Message.RecipientType.TO);

if (fr != null)
for (int i = 0; i < fr.length; i++) { from += fr[i] + " , "; }


if (t != null)
for (int i = 0; i < t.length; i++) { to +=t[i] + " , "; }

subject = m.getSubject();
sdate = m.getSentDate();

Object content = m.getContent();
if (content instanceof String) {
mess=(String)content;
}
else{
mess="Unrecognized Content Type";
}
}catch(Exception e) { System.out.println(e.toString());}
}

}

and writing this way:
MyMessage mm=new MyMessage(msg);
try{
FileOutputStream fos= new FileOutputStream("sent_mails",true);
ObjectOutputStream os=new ObjectOutputStream(fos);
os.writeObject(mm);
os.flush();
os.close();
fos.close();

while reading out from a fileFileInputStream fs= new FileInputStream("sent_mails");
ObjectInputStream s=new ObjectInputStream(fs);
MyMessage m;
m=(MyMessage)s.readObject();
System.out.println(m + "
");
m=(MyMessage)s.readObject();
System.out.println(m + "
");
s.close();
fs.close();
it is able to read only one object and gives
"java.io.StreamCorruptedException Type code Outof range is -84"

what can be the problem ? please help.

   <<Less
About | Sitemap | Contact