Save the information from an ArrayList after restarting the program
How can i save an information stored in an ArrayList object after the program has been terminated and started again?
I save all the information from the ArrayList object in a file.
I have an idea-to check if the file exists and if so the information coppied in the file,copies in the arraylist. Can I achieve that or is there another way to do so?
Re: Save the information from an ArrayList after restarting the program
You could serialize the object (see Discover the secrets of the Java Serialization API ). If the List contains any object that does not implement Serializable, then you must somehow implement it. You could also write out some code which can save the list as xml. Depending upon how complex the List objects are, this could be easy or hard, but in my opinion is a bit more flexible that Serialization
Re: Save the information from an ArrayList after restarting the program
there are several ways to save objects (in you case: the list) to a file and read it back to an object. the easiest way i know is to use Xstream. it works on everything, no matter if it's serializable or not.
XStream - Two Minute Tutorial
Re: Save the information from an ArrayList after restarting the program
Quote:
Originally Posted by
hamsterofdeath
there are several ways to save objects (in you case: the list) to a file and read it back to an object. the easiest way i know is to use Xstream. it works on everything, no matter if it's serializable or not.
XStream - Two Minute Tutorial
how to install the libraries in Eclipse? I think XStream will do the trick
Re: Save the information from an ArrayList after restarting the program
google "eclipse tutorial"