I have written multiple objects in the same file over last 2 weeks. Each time (probably million times) I called:
try(ObjectOutputStream output=new ObjectOutputStream(new FileOutputStream(new File("somefile"),true))) {
output.writeObject(someobject);
output.close();
}
Now when I try to read it using:
try(ObjectInputStream input=new ObjectInputStream(new FileInputStream(new File("somefile")))) {
while(true) {
PROCESS_IT(input.readObject());
}
}
It reads only first object and gives error:
java.io.StreamCorruptedException: invalid type code: AC
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1379)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371)
I know now that I should have overridden the streamheader while writing these objects (Appending to an ObjectOutputStream)
But it took me two weeks already to get the results in this "somefile". Can I somehow still read all the objects by skipping the corrupt bytes/headers? Please advise. Thanks