Article View: borland.public.jbuilder.java.language
Article #15766Re: Serialization?!?! URGENT!
From: E.K.A.T
Date: Wed, 28 Apr 1999 00:00
Date: Wed, 28 Apr 1999 00:00
53 lines
2466 bytes
2466 bytes
You need to reset the stream
ie with the reset method
Syed Tarique wrote in message <372713A8.F7A5D8C6@castlenetworks.com>...
>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:
<7g7a1n$btt$1@news4.svr.pol.co.uk>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<372713A8.F7A5D8C6@castlenetworks.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,1443dd3a6c837160 X-Google-Attributes: gidf74b3,public From: "E.K.A.T" <alan@ekat.freeserve.co.uk> Subject: Re: Serialization?!?! URGENT! Date: 1999/04/28 Message-ID: <7g7a1n$btt$1@news4.svr.pol.co.uk> X-Deja-AN: 471917096 References: <372713A8.F7A5D8C6@castlenetworks.com> X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 X-Complaints-To: abuse@theplanet.net X-Trace: news4.svr.pol.co.uk 925313911 12221 62.136.29.24 (28 Apr 1999 15:38:31 GMT) Organization: Customer of Planet Online NNTP-Posting-Date: 28 Apr 1999 15:38:31 GMT Newsgroups: borland.public.jbuilder.java.language