Reputation: 41
Am writing three objects to a binary file using below code in java.
oout = new ObjectOutputStream(new FileOutputStream(fileName));
oout.writeObject(objClass1);
oout.writeObject(objClass2);
oout.writeObject(objClass3);
Then how can i want to modify some data in the objClass1 and update the file? Also append objClass3 to the end of file.
Thanks....
Upvotes: 1
Views: 633
Reputation: 8090
You cannot write at the beginning of a file that has contents so you need to read the content , update what you want and write again all the content... this isn't very efficient so i propose 2 solutions :
Upvotes: 1
Reputation: 136062
You cannot update just one object, you need to overwrite the whole file. Read all 3 objects from file then write them back with new objClass1 version
Upvotes: 3