Article View: borland.public.jbuilder.java.language
Article #15763Serialization?!?! URGENT!
From: Syed Tarique
Date: Wed, 28 Apr 1999 00:00
Date: Wed, 28 Apr 1999 00:00
45 lines
2121 bytes
2121 bytes
Hello all!
I am trying to write objects to a file and read back the objects from
the file. I can read only one object but if I try to read the next
object I get the folowing exception...
java.io.StreamCorruptedException: Type code out of range, is -84
at java.io.ObjectInputStream.peekCode(Compiled Code)
at java.io.ObjectInputStream.refill(Compiled Code)
at java.io.ObjectInputStream.readObject(Compiled Code)
at java.io.ObjectInputStream.readObject(Compiled Code)
at test.OFrame.jbInit(Compiled Code)
at test.OFrame.<init>(OFrame.java:17)
at test.ObjectReadTest.<init>(ObjectReadTest.java:11)
at test.ObjectReadTest.main(ObjectReadTest.java:30)
The code sample I am using
//Writing
FileOutputStream out = new FileOutputStream(filename, true);
ObjectOutputStream outo = new ObjectOutputStream(out);
outo.writeObject(t);
outo.flush();
outo.close();
// I am writing the same object twice in the file
//and read back the two object
// I can read the first Object without any problem but problem occurs
when I read second object
//Reading
FileInputStream inp = new
FileInputStream("c:\\javawebserver1.1.1\\castlenetworks\\data\\traps\\sce11.dat");
ObjectInputStream inpo = new ObjectInputStream(inp);
PowerTrap t = (PowerTrap)inpo.readObject();
System.out.println("Object Read From File" + t);
t = (PowerTrap)inpo.readObject();
System.out.println("Object Read From File" + t);
Any suggestions will be highly appreciated.
Thanks
-Syed
Technical Details
Message-ID:
<372713A8.F7A5D8C6@castlenetworks.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,1443dd3a6c837160,start X-Google-Attributes: gidf74b3,public From: Syed Tarique <starique@castlenetworks.com> Subject: Serialization?!?! URGENT! Date: 1999/04/28 Message-ID: <372713A8.F7A5D8C6@castlenetworks.com> X-Deja-AN: 471882963 Content-Transfer-Encoding: 7bit Organization: Another Netscape Collabra Server User Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language