title: How to empty file content and then append text multiple times
body: <p>I have a file (file.txt), and I need to empty his current content, and then to append some text multiple times.</p>
  
  <p>Example: file.txt current content is:</p>
  
  <blockquote>
    <p>aaa</p>
    
    <p>bbb</p>
    
    <p>ccc</p>
  </blockquote>
  
  <p>I want to remove this content, and then to append the first time:</p>
  
  <blockquote>
    <p>ddd</p>
  </blockquote>
  
  <p>The second time:</p>
  
  <blockquote>
    <p>eee</p>
  </blockquote>
  
  <p>And so on...</p>
  
  <p>I tried this:</p>
  
  <pre><code>// empty the current content
  fileOut = new FileWriter("file.txt");
  fileOut.write("");
  fileOut.close();
  
  // append
  fileOut = new FileWriter("file.txt", true);
  
  // when I want to write something I just do this multiple times:
  fileOut.write("text");
  fileOut.flush();
  </code></pre>
  
  <p>This works fine, but it seems inefficient because I open the file 2 times just for remove the current content.</p>