permaculture playing cards*
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Problem with Objectuinputstream" Watch "Problem with Objectuinputstream" New topic
Author

Problem with Objectuinputstream

viswanath sigamala
Greenhorn

Joined: Feb 06, 2007
Posts: 11
Hi,

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.

Thanks,
Viswanath
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8833
    
    7

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
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
viswanath sigamala
Greenhorn

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

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
ObjectOutputStream -- Error.
B&S: Invalid Stream Header
Java I/O
problem in serialization
Closing Stream