I have following code to serialize my data into a file:
out = new ObjectOutputStream(new FileOutputStream(file));
out.writeObject(chunk);
out.flush();
I read with the following:
in = new ObjectInputStream(new FileInputStream(file));
Chunk chunk = (Chunk) in.readObject();
The weird thing is, when I read the data, all members are set to default and I get no data back that I wrote before.
If I use the XML variant all works fine.
e = new XMLEncoder(new FileOutputStream(file));
e.writeObject(chunk);
e.flush();
and
e = new XMLDecoder(new FileInputStream(file));
Chunk chunk = (Chunk) e.readObject();
What is wrong with the binary format?
Update
Ok i got this now: Chunk is a complex class with classes in, other classes with other classes in and so on. At some point the contained classes is declared as Object and should be Serializable. As Steve mentioned.
Thank you for your answers.