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?