I have a number of objects (of the same class) serialized into a file. But while deserializing it, only the first serialized object is deserialized.
Code for serializing:
public void save() {
File f = new File("vehicule.txt");
try {
if(!f.exists()) f.createNewFile();
} catch(IOException e) {
}
try {
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(f,true));
oos.writeObject(this);
} catch(IOException e) {
}
}
I think the problem is with:
Vehicule v;
while( (v = (Vehicule)ois.readObject()) != null )
Is there a better way to check for the end of the file?