title: File truncate operation in Java
body: <p>What is the best-practice way to truncate a file in Java? For example this dummy function, just as an example to clarify the intent:</p>
  
  <pre><code>void readAndTruncate(File f, List&lt;String&gt; lines)
          throws FileNotFoundException {
      for (Scanner s = new Scanner(f); s.hasNextLine(); lines.add(s.nextLine())) {}
  
      // truncate f here! how?
  
  }
  </code></pre>
  
  <p>The file can not be deleted since the file is acting as a place holder.</p>