How to add text to a text file in java?
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/1625234/how-to-append-text-to-an-existing-file-in-java">How to append text to an existing file in Java</a>  </p>
</blockquote>



<p>I want to add data to a text file. So it's one after another...so something like:</p>

<pre><code>1
2
3
&lt;add more here&gt;
</code></pre>

<p>But I don't want the text from the file to be deleted at all. This is the code i'm using atm, but it replaces what ever is in the file. Could someone please tell me how to do what I asked. Thanks.</p>

<pre><code>    FileWriter fstream = new FileWriter("thefile.txt");
    BufferedWriter out = new BufferedWriter(fstream);
    out.write("blabla");
    out.close();
      }catch (Exception e){//Catch exception if any
  System.err.println("Error: " + e.getMessage());
   }
}
</code></pre>
