title: Java - how to replace file contents?
body: <p>I have a file that contains only a very small amount of information that needs to be updated periodically.  In other words, I want to truncate the file before writing to it.  The easiest solution I found was to delete and create it again as shown here:</p>
  
  <pre><code>File myFile = new File("path/to/myFile.txt");
  myFile.delete();
  myFile.createNewFile();
  // write new contents
  </code></pre>
  
  <p>This 'works' fine, but is there a better way?</p>