KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Is it not possible to append to an ObjectOutputStream ? I am trying to append to a list of objects. Following snippet is a function that is called whenever a job is finished. FileOutputStream fos = new FileOutputStream (preferences.getAppDataLocation() + "history" , true); ObjectOutputStream out = new ObjectOutputStream(fos); out.writeObject( new Stuff(stuff) ); out.close(); But when I try to read it I only get the first in the file. Then I get java.io.StreamCorruptedException . To read I am using FileInputStream fis = new FileInputStream ( preferences.getAppDataLocation() + "history"); ObjectInputStream in = new ObjectInputStream(fis); try{ while(true) history.add((Stuff) in.readObject()); }catch( Exception e ) { System.out.println( e.toString() ); } I do not know how many objects will be present so I am reading while there are no exceptions. From what Google says this is not possible. I was wondering if anyone knows a way?
Tags (comma-separated)
Save Edits
Cancel