File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Saving Program Data... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Saving Program Data..." Watch "Saving Program Data..." New topic

Saving Program Data...

Martin Clifford

Joined: Dec 02, 2002
Posts: 23
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

Joined: Jul 02, 2001
Posts: 118
You can use the ObjectInputStream and ObjectOutputStream in the package to do this. Please note that this code hasn't been tested.

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.
[ January 03, 2003: Message edited by: Peter Kristensson ]
jQuery in Action, 3rd edition
subject: Saving Program Data...
It's not a secret anymore!