title: Atomic file write operations (cross platform)
body: <p>How do I build up an atomic file write operation? The file is to be written by a Java service and read by python scripts.<br>
  For the record, reads are far greater than writes. But the write happens in batches and tend to be long. The file size amounts to mega bytes.  </p>
  
  <p><em>Right now my approach is:</em></p>
  
  <ul>
  <li>Write file contents to a temp file in
  same directory</li>
  <li>Delete old file</li>
  <li>Rename temp file to old filename.</li>
  </ul>
  
  <p>Is this the right approach? How can avoid conditions where the old file is deleted but the new filename is yet to be renamed?   </p>
  
  <p>Do these programming languages (<em>python and java</em>) offer constructs to lock and avoid this situation? </p>