This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ObjectOutputStream serializable HELP!!  RSS feed

 
Hung Chan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For "ObjectOutputStream", Is there any way to append addition data to file without destroying any existing data.

Below is my code, I try to append "userAccount" object to the end of file. However, it doesn't work. The existing data is over-written by the new data. I looked at the ObjectOutputStream doc in JavaDoc... ObjectOutputStream doesn't have any "append" mode...

I need to use Object serializable to update the file with addition information. Any idea how to do it?


public void store(Account userAccount) throws IOException {

FileOutputStream fos = new FileOutputStream("c:\\tmp.bin");
ObjectOutputStream oos = new ObjectOutputStream(fos);

oos.writeObject(userAccount);
}
 
Ramesh Aiyappan
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using the append parameter of the FileOutputStream.
FileOutputStream fos = new FileOutputStream("C:\\temp.bin",true);
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!