How do you append to a text file instead of overwriting it in Java?
<p>I am trying to add a line to a text file with Java. When I run my program, I mean to add a simple line, but my program is removing all old data in the text file before writing new data.</p>

<p>Here is the code:</p>

<pre><code> FileWriter fw = null;
  PrintWriter pw = null;
    try {
        fw = new FileWriter("output.txt");
        pw = new PrintWriter(fw);

    pw.write("testing line \n");
        pw.close();
        fw.close();
    } catch (IOException ex) {
        Logger.getLogger(FileAccessView.class.getName()).log(Level.SEVERE, null, ex);
    }
</code></pre>
