title: using for loop write lines one by one in file using java
body: <pre><code>for(i=0;i&lt;10;i++){
      String output = output + "Result "+ i +" : "+ ans +"\n";   //ans from other logic
      FileWriter f0 = new FileWriter("output.txt");
      f0.write(output);
  }
  </code></pre>
  
  <p>but it doesn't work,
  please give some help for <code>append</code> or <code>PrintWriter</code> method, i have no idea how to use these methods.</p>
  
  <p>i need file output like</p>
  
  <pre><code>Result 1 : 45           //here 45 is ans
  Result 2 : 564856
  Result 3 : 879
  .
  .
  .
  .
  Result 10 : 564
  </code></pre>
  
  <p>thanks</p>