• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

object serialization to file

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?


 
I love a good mentalist. And so does this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic