title: java - Can't get "append mode" on Filewriter to work for me
body: <p>I've been all over the search and it seems like the given answers just don't work for me.</p>
  
  <p>My code is relatively simple, it generates an array of Objects, populates it with some random strings and then tries to output to a file.  The idea is basically to generate a CSV file with some names, login names, passwords, etc.  and the names are strings of random letters (long story, it's for mass-populating an environment with users...)</p>
  
  <p>I have a "Writer" class like this:</p>
  
  <pre><code>    public class Writer {
      public static void log(String message) throws IOException { 
  
       PrintWriter out = new PrintWriter(new FileWriter("testlog.txt"), true); 
       out.println(message);
  
    out.close();
  }
  }
  </code></pre>
  
  <p>And a loop like this:</p>
  
  <pre><code>    for (int y=0; y &lt; num_names; y++) {
             try {
              Writer.log(arrayTest[y].first + "," + arrayTest[y].last + "," +     arrayTest[y].loginName + "," + arrayTest[y].password +
                      "," + arrayTest[y].email);
          } catch (IOException ex) {
              Logger.getLogger(Csvgenerator.class.getName()).log(Level.SEVERE, null, ex);
          }
  
  
     System.out.println(arrayTest[y].first + "," + arrayTest[y].last + "," + arrayTest[y].loginName + "," + arrayTest[y].password + 
             "," + arrayTest[y].email);    
  
   }
  </code></pre>
  
  <p>My expectation is that I will loop through and for each object in arrayTest[] I output a single line of data to the file.
  I included the System.out.println just for debugging.</p>
  
  <p>When I run my code, the System.out.println proves that it works properly -- I get a list of 10 rows.  (num_names = 10 here)  so this proves that each time I get to this line of code, I have a unique "row" of data which gets printed out.</p>
  
  <p>However, at the end of the run, the file "testlog.txt" only contains a single line -- the very last row in my output.</p>
  
  <p>I've tried "out.append" instead of "out.println" but no difference.  It appears as though every time I call the logger it's creating the file anew for some reason.</p>
  
  <p>So in other words if my console output (from the system.out.println) looks like this:</p>
  
  <pre><code>nxoayISPaX,aNQWbAjvWE,nanqwbajvwe,P@ssw0rd!,nanqwbajvwe@mylab.com
  RpZDZAovgv,QOfyNRtIAN,rqofynrtian,P@ssw0rd!,rqofynrtian@mylab.com
  SajEwHhfZz,VziPeyXmAc,svzipeyxmac,P@ssw0rd!,svzipeyxmac@mylab.com
  sifahXTtBx,MRmewORtGZ,smrmewortgz,P@ssw0rd!,smrmewortgz@mylab.com
  PlepqHzAxE,MQUJsHgEgy,pmqujshgegy,P@ssw0rd!,pmqujshgegy@mylab.com
  VKYjYGLCfV,nuRKBJUuxW,vnurkbjuuxw,P@ssw0rd!,vnurkbjuuxw@mylab.com
  YgvgeWmomA,ysKLVSZvaI,yysklvszvai,P@ssw0rd!,yysklvszvai@mylab.com
  feglvfOBUX,UTIPxdEriq,futipxderiq,P@ssw0rd!,futipxderiq@mylab.com
  RAQPPNajxR,vzdIwzFHJY,rvzdiwzfhjy,P@ssw0rd!,rvzdiwzfhjy@mylab.com
  DeXgVFClyg,IEuUuvdWph,dieuuuvdwph,P@ssw0rd!,dieuuuvdwph@mylab.com
  </code></pre>
  
  <p>Then testlog.txt only contains a single line:</p>
  
  <pre><code>DeXgVFClyg,IEuUuvdWph,dieuuuvdwph,P@ssw0rd!,dieuuuvdwph@mylab.com
  </code></pre>
  
  <p>How do I force this to keep using the same file and just append new lines?</p>