try {
if(!f.exists()) f.createNewFile();
} catch(IOException e) {
}
You don't need any of that. new FileOutputStream()
will create the file.
new ObjectOutputStream(new FileOutputStream(f,true))
You can't append to an ObjectOutputStream
. There are headers in there that ObjectInputStream
won't understand if it encounters them in the middle of a stream.
while( (v = (Vehicule)ois.readObject()) != null )
Is there a better way to check for the end of the file?
There's nothing in the Javadoc about readobject()
returning null
at EOS. readObject()
returns null
if and only if you wrote a null
.
The correct technique is to catch EOFException
, close the stream, and break out of the loop.