File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes Problem with Objectuinputstream Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Reply 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: 7921

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
Saloon Keeper

Joined: Oct 27, 2005
Posts: 18365

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
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: 18652
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
 
 
subject: Problem with Objectuinputstream
 
Threads others viewed
B&S: Invalid Stream Header
Closing Stream
Java I/O
problem in serialization
ObjectOutputStream -- Error.
MyEclipse, The Clear Choice