Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Problem with Objectuinputstream

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 9615
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you write nonav.log with an ObjectOutputStream? If not, you cannot read it with an ObjectInputStream.
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also check whether your ObjectOutputStream was flushed and closed properly.
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Sheriff
Posts: 22030
108
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
viswanath sigamala
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Guys for Help.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
LOOK! OVER THERE! (yoink) your tiny ad is now my tiny ad.
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic