title: Is there a better way to overwrite file contents?
body: <p>I'm looking to overwrite the contents of a file that already exists. Obviously I could just create a new file that overwrites the old one, as per <a href="https://stackoverflow.com/a/1016291/1390487">this answer</a>. However, I'm writing a program that is going to be doing this potentially quite a few times, and I want to cut down unnecessary overhead as much as possible.</p>
  
  <p>So my question is: is there a better way of simply rewriting the contents of the file itself, instead of writing a 'new' file that replaces the old one? Or is the overhead of simply overwriting the entire file contents roughly equivalent to the overhead of creating the new file and then writing to it? (For the record, these files are only 1 KB large.)</p>