• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

ObjectOutputStream serializable HELP!!

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
}
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try using the append parameter of the FileOutputStream.
FileOutputStream fos = new FileOutputStream("C:\\temp.bin",true);
 
After some pecan pie, you might want to cleanse your palatte with this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic