title: Java: Serialize & DeSerialize ArrayList
body: <p>I have a class <code>Book()</code>, <code>Author()</code> and a class <code>CollectionOfBooks()</code>(where I stock all the books in an ArrayList). Then I have my interface where I have a menu where I can add/list/remove/search books. Everything works fine. But, I also want to save my books in a file when I exit the program so when the program ends I call this method(<code>BooksIO()</code> is the class for serialize&amp;deserialize):</p>
  
  <pre><code>public void exitProgram() throws IOException{
          System.out.println("Program shuts down, cya!");
          BooksIO.outputFile(); // to save my books to the file
      }
  </code></pre>
  
  <p>I am not sure if the books are saved because when I start the program the books don't show up:</p>
  
  <pre><code>public static void main(String[] args) throws IOException, ClassNotFoundException {
          UserInterface menu = new UserInterface();
          BooksIO.inputFile(); // get the books from the saved file to the library
          menu.run();
      }
  </code></pre>
  
  <p>I am not sure what I am doing wrong, can someone help me?
  The class for Serialize &amp; DeSerialize :  </p>
  
  <pre><code>    public class BooksIO {
  
              public static  void outputFile() throws IOException{
                  CollectionOfBooks library = new CollectionOfBooks(); //where the books are saved in an ArrayList
                  FileOutputStream fout=null;
                  ObjectOutputStream oos=null;
                  try{
                      fout = new FileOutputStream ("stefi.ser");
                      oos=new ObjectOutputStream(fout);
                      // I try to save my library to the file
                      oos.writeObject(library.Books); 
  
                      System.out.println("Serializing successfully completed");
  
                      for(Book c: library.Books){
                          System.out.println(c.toString());
                      }
                  } catch (IOException ex){
                      System.out.println(ex);
                  }finally{
                      try{
                          if(fout!=null) fout.close();
                          if(oos!=null) oos.close();
                      } catch (IOException e){
  
                      }
                  }
              }
  
              public static void inputFile() throws IOException, ClassNotFoundException{
  
                  CollectionOfBooks library = new//where my books are saved in an ArrayList of type Book CollectionOfBooks();//where my books are saved in an ArrayList of type Book
                  ObjectInputStream ois = null;
                  try{
                      FileInputStream fin = new FileInputStream("stefi.ser");
                      ois = new ObjectInputStream(fin);
                      // try to get my books from the file and save it in the library
                      library.Books  = (ArrayList&lt;Book&gt;)ois.readObject();
                      System.out.println("Deserializing successfully completed");
  
                      for(Book c: library.Books){
                          System.out.println(c.toString());
                      }
  
                  }catch (ClassNotFoundException e){
                      System.out.println("The class for this type of objects"+
                              "does not exist in this application!");
                      throw e;
                  }finally{
                      try{
                          if(ois!=null){
                              ois.close();
                          }
                      }catch (IOException e){
  
                      }
                  }
              }
          }
  </code></pre>