title: writing an arraylist to file
body: <p>I'm having some trouble writing an array list to file using printwriter. I've tried another way that worked but it wouldn't print all the things from the array list just one. This is the way I'm trying at the moment and it won't print anything.</p>
  
  <pre><code>datArrayList = new ArrayList&lt;theAccounts&gt;();
  File file = new File("output.txt");
  
  public void writer() throws FileNotFoundException, IOException{ 
  
  
     PrintWriter pw = new PrintWriter(new FileOutputStream(file));
     FileOutputStream fo = new FileOutputStream(file);
     int datList = datArrayList.size();
  
     for (int i = 0; i &lt; datList; i++){
      pw.write(datArrayList.get(i).toString() + "\n");
    }
  </code></pre>
  
  <p>Can anyone tell me what i should be doing to write all the items in the array to the output file? thank you :)</p>