Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Saving Program Data...

 
Martin Clifford
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone!
I'm probably barely above beginner level, if that, but I am trying to write a program in which the user will enter some data (method unknown), and I want to store this information (at least during runtime), inside one of the many collections classes. That I can do. What I am unfamiliar with is how you go about SAVING that collection to a file, and also how you would LOAD it from the file.
I have a strong suspicion (for some reason that word looks mispelled), that it has something to do with serialization, but I am unsure right now. Does anyone have any helpful hints, or could anyone point me in the right direction to get started? Don't want solutions, just gentle nudges so I can start on the right path )
Thanks in advance!
 
Peter Kristensson
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hiya.
You can use the ObjectInputStream and ObjectOutputStream in the java.io package to do this. Please note that this code hasn't been tested.
Writing:

and for reading:

This is possible due to the fact that all classes that implements the Collection interface are Serializable if I remember correclty. Take into consideration however that the things that you put in you Collection has to be serializable also.
/Peter
[ January 03, 2003: Message edited by: Peter Kristensson ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic