wood burning stoves 2.0*
The moose likes I/O and Streams and the fly likes Problem with Objectuinputstream Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Problem with Objectuinputstream" Watch "Problem with Objectuinputstream" New topic

Problem with Objectuinputstream

viswanath sigamala

Joined: Feb 06, 2007
Posts: 11

FileInputStream fis = new FileInputStream("c:\\nonav.log");
ObjectInputStream ois = new ObjectInputStream(fis);
String today = (String) ois.readObject();
byte[] bytedata= today.getBytes();

Above code i am getting below exception:

java.io.StreamCorruptedException: invalid stream header
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:768)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:283)
at com.ibm.test.ReadZipPObjectinputstream.main(ReadZipPObjectinputstream.java:56)

Please help me in resolving the issue.

Joe Ess

Joined: Oct 29, 2001
Posts: 8839

Did you write nonav.log with an ObjectOutputStream? If not, you cannot read it with an ObjectInputStream.

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Prakash Subramanian
Ranch Hand

Joined: Feb 03, 2005
Posts: 32
Also check whether your ObjectOutputStream was flushed and closed properly.
amitabh mehra
Ranch Hand

Joined: Dec 05, 2006
Posts: 98
Originally posted by Prakash Subramanian:
Also check whether your ObjectOutputStream was flushed and closed properly.

Prakash, can not flushing and closing of ObjectOutputStream cause this exception? I have doubts.
Rob Spoor

Joined: Oct 27, 2005
Posts: 19655

I don't think it caused this exception, but it can sure cause exceptions.

I once closed the backing OutputStream instead of the ZipOutputStream, and as a result the file was a corrupt ZIP file.

How To Ask Questions How To Answer Questions
viswanath sigamala

Joined: Feb 06, 2007
Posts: 11
Thanks Guys for Help.
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
I think it could possibly cause this exception - for example, if the full header never got written in the first place, because some of it was still in a buffer somewhere when the program terminated.

"I'm not back." - Bill Harding, Twister
I agree. Here's the link: http://aspose.com/file-tools
subject: Problem with Objectuinputstream
Similar Threads
problem in serialization
ObjectOutputStream -- Error.
B&S: Invalid Stream Header
Java I/O
Closing Stream