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 2 of 2

Thread: Serialization of lists

  1. #1
    Member
    Join Date
    Feb 2011
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Serialization of lists

    I have a list which I save by the following:
    	public void saveList(ArrayUnsortedList<Wrestler> listOfWrestlersToSave) {
    		System.out.println(listOfWrestlersToSave);
        	try{
    		ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(FILENAME));
    		out.close();
        	}
        	catch(Exception e){
        		System.out.println("Couldnt save");
        	}
     
    	}

    But I want to load this saved list on start of the program so I tried this:
    	public SList loadList(String fileName){
    		  SList loadedListOfWrestlers = new SArrayIndexedList();
     
    		try{
    			ObjectInputStream in = new ObjectInputStream(new FileInputStream(fileName));	
    			loadedListOfWrestlers = (SList)in.readObject();
    			System.out.println(loadedListOfWrestlers);
    		}
    		catch(Exception e){
    			System.out.println(e);
    		}
    		return loadedListOfWrestlers;
     
    	}
    Additional details:
    SList is a list (an abstract data type) which is an unsorted array that implements Serializable.
    fileName is a string containing the name of the .dat file in which my saveList() method saved the list to.

    But when I run loadlist() I get java.io.EOFException. I know few details are provided here, but I feel like if I provide all the details it'd be too much. So, in general, what could potentially be wrong in my load function that causes me to get java.io.EOFException?


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

    Default Re: Serialization of lists

    I have a list which I save by the following:...
    Where do you actually write the List to the File? ie through the writeObject method of ObjectOutputStream

Similar Threads

  1. DefaultTableModel Serialization
    By newbie in forum Java Theory & Questions
    Replies: 8
    Last Post: August 15th, 2011, 07:46 PM
  2. [SOLVED] Linked Lists
    By lieles in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 6th, 2011, 08:39 AM
  3. Sub class Serialization
    By Param in forum Java Theory & Questions
    Replies: 6
    Last Post: April 23rd, 2010, 02:04 AM
  4. Exception and Serialization Problems
    By chrisych in forum Exceptions
    Replies: 0
    Last Post: February 7th, 2010, 11:30 AM
  5. serialization problem
    By Park in forum Object Oriented Programming
    Replies: 2
    Last Post: November 26th, 2009, 04:44 PM