title: Is this the best way to rewrite the content of a file in Java?
body: <p>I want to rewrite the contents of a file.</p>
  
  <p>What I have thought of so far is this:</p>
  
  <ol>
  <li>Save the file name</li>
  <li>Delete the existing file</li>
  <li>Create a new empty file with the same name</li>
  <li>Write the desired content to the empty file</li>
  </ol>
  
  <p>Is this the best way? Or is there a more direct way, that is, not having to delete and create files, but simply change the content?</p>