This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

object serialization to file  RSS feed

 
murat gungor
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having trouble doing serialization of multiple objects to a file. When I use the following code, which opens the file, writes all objects and closes it, it works fine. But when I open the same file and append some other objects, I get "java.io.StreamCorruptedException: Type code out of range, is -84" error.
first version:
ObjectOutputStream oos = new ObjectOutputStream(
new FileOutputStream(fn));
oos.writeObject(new String("string 1"));
oos.writeObject(new String("string 2"));
oos.flush();
oos.close();
second version:
ObjectOutputStream oos = new ObjectOutputStream(
new FileOutputStream(fn,true));
oos.writeObject(new String("string 3"));
oos.flush();
oos.close();
deserialization code is same for both, and only works for first version...what's wrong?


 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!