title: Is java.io.FileWriter designed only for a single use?
body: <p>I'm building a program that constantly writes to the same file, using <code>java.io.FileWriter</code>.</p>
  
  <p>During run-time, whenever I need to update the file, I call a method that <a href="https://stackoverflow.com/questions/9887520/java-create-temp-file-and-replace-with-original">writes "properly"</a> and uses a class-level FileWriter. The problem starts on the second <code>.write</code> call, when the FileWriter starts <strong>appending</strong> to the file, instead of <strong>overwriting</strong> it.</p>
  
  <pre><code>public class Example {
      private FileWriter fw = new FileWriter("file's path", false);
  
      public void writeToFile(String output) {
          fw.write(output);
          fw.flush();
      }
  }
  </code></pre>
  
  <p>I'm suspecting that somehow the FileWriter's "memory" keeps its previously written data, but I don't want to close and initialize it for every call, as it seems wasteful.</p>
  
  <ol>
  <li>Do I even need the <code>.flush</code> call after each <code>.write</code> call?</li>
  <li>Do I have another option but initializing the FileWriter and <code>.close</code>-ing it on every call?</li>
  </ol>
  
  <p>(I tried looking in older questions, but they all seem to deal with FileWriters that <strong>won't</strong> append, or theoretical <code>FileWriter.flush</code> interpretations)</p>