Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Save the information from an ArrayList after restarting the program

  1. #1
    Member
    Join Date
    Aug 2010
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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?


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default 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

  3. #3
    Junior Member
    Join Date
    Aug 2010
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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

  4. #4
    Member
    Join Date
    Aug 2010
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Save the information from an ArrayList after restarting the program

    Quote Originally Posted by hamsterofdeath View Post
    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

  5. #5
    Junior Member
    Join Date
    Aug 2010
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Save the information from an ArrayList after restarting the program

    google "eclipse tutorial"

Similar Threads

  1. Can't get it to save stuff with JFileChooser
    By javapenguin in forum What's Wrong With My Code?
    Replies: 35
    Last Post: August 11th, 2010, 04:13 AM
  2. Java Question Need Help Restarting the Values of Variables from Random Numbers So Out
    By JavaStudent1990 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 24th, 2010, 02:25 PM
  3. Java JTextPane Save
    By ikurtz in forum File I/O & Other I/O Streams
    Replies: 9
    Last Post: April 28th, 2010, 01:02 AM
  4. Arraylist Save and Load
    By frankycool in forum Collections and Generics
    Replies: 1
    Last Post: November 14th, 2009, 06:48 AM
  5. Saving .jsp page as .pdf file while generating report for struts based web application
    By ravindra_kumar_tiwari in forum JavaServer Pages: JSP & JSTL
    Replies: 3
    Last Post: August 12th, 2008, 09:32 AM