Object serialization and try/catch

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 835 Views - Last Post: 30 January 2013 - 05:13 PM Rate Topic: -----

#16 IceHot  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 199
  • Joined: 28-August 12

Re: Object serialization and try/catch

Posted 30 January 2013 - 05:13 PM

What I need to know how to do (and what my book doesn't explain!) is how to append objects to a file every time a program runs. Is anyone going to help on this!? It seems that no matter what I try, I get some exception thrown of some sort. I have tried the advice found here: http://stackoverflow...ectoutputstream and I get a different error! I am not asking for someone to give me code, I am asking for UNDERSTANDING. It seems like whenever the program that writes data to the file is being run, it writes a header. Since only one header is being run, it would make sense to override the function writing the header, which is what the guy in that link ended up doing. However, it is complaining of improper header when I try to execute some example code (that writes data to a file every time the program is run) twice.

It keeps throwing StreamCorruptedException. Here is the error I get after doing what I did above:
java.io.StreamCorruptedException: invalid stream header: 79737200
at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
at java.io.ObjectInputStream.<init>(Unknown Source)
at ReadData.openfile(ReadData.java:15)
at SerializationTest.main(SerializationTest.java:12)

This post has been edited by IceHot: 30 January 2013 - 09:47 PM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2