I want to rewrite the contents of a file.
What I have thought of so far is this:
- Save the file name
 - Delete the existing file
 - Create a new empty file with the same name
 - Write the desired content to the empty file
 
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?