title: Java - How Can I Write My ArrayList to a file, and Read (load) that file to the original ArrayList?
body: <p>I am writing a program in Java which displays a range of afterschool clubs (E.G. Football, Hockey - entered by user). The clubs are added into the following <code>ArrayList</code>:</p>
  
  
  
  <pre class="lang-java prettyprint-override"><code>private ArrayList&lt;Club&gt; clubs = new ArrayList&lt;Club&gt;();
  </code></pre>
  
  <p>By the followng Method:</p>
  
  <pre class="lang-java prettyprint-override"><code>public void addClub(String clubName) {
      Club club = findClub(clubName);
      if (club == null)
          clubs.add(new Club(clubName));
  }
  </code></pre>
  
  <p>'Club' is a class with a constructor - name:</p>
  
  <pre class="lang-java prettyprint-override"><code>public class Club {
  
      private String name;
  
      public Club(String name) {
          this.name = name;
      }
  
      //There are more methods in my program but don't affect my query..
  }
  </code></pre>
  
  <p>My program is working - it lets me add a new Club Object into my arraylist, i can view the arraylist, and i can delete any that i want etc. </p>
  
  <p>However, I now want to save that arrayList (clubs) to a file, and then i want to be able to load the file up later and the same arraylist is there again.</p>
  
  <p>I have two methods for this (see below), and have been trying to get it working but havent had anyluck, any help or advice would be appreciated.</p>
  
  <p>Save Method (fileName is chosen by user)</p>
  
  <pre class="lang-java prettyprint-override"><code>public void save(String fileName) throws FileNotFoundException {
      String tmp = clubs.toString();
      PrintWriter pw = new PrintWriter(new FileOutputStream(fileName));
      pw.write(tmp);
      pw.close();
  }
  </code></pre>
  
  <p>Load method (Current code wont run - File is a string but needs to be Club?</p>
  
  <pre class="lang-java prettyprint-override"><code>public void load(String fileName) throws FileNotFoundException {
      FileInputStream fileIn = new FileInputStream(fileName);
      Scanner scan = new Scanner(fileIn);
      String loadedClubs = scan.next();
      clubs.add(loadedClubs);
  }
  </code></pre>
  
  <p>I am also using a GUI to run the application, and at the moment, i can click my Save button which then allows me to type a name and location and save it. The file appears and can be opened up in Notepad but displays as something like Club@c5d8jdj (for each Club in my list)</p>