title: How to safely update a file that has many readers and one writer?
body: <p>I have a set of files.  The set of files is read-only off a NTFS share, thus can have many readers. Each file is updated occasionally by one writer that has write access.</p>
  
  <p>How do I ensure that:</p>
  
  <ol>
  <li>If the write fails, that the previous file is still readable</li>
  <li>Readers cannot hold up the single writer</li>
  </ol>
  
  <p>I am using Java and my current solution is for the writer to write to a temporary file, then swap it out with the existing file using <code>File.renameTo()</code>.  The problem is on NTFS, <code>renameTo</code> fails if target file already exists, so you have to delete it yourself.  But if the writer deletes the target file and then fails (computer crash), I don't have a readable file.</p>
  
  <p><strike>nio's FileLock only work with the same JVM, so it useless to me.</strike></p>
  
  <p>How do I safely update a file with many readers using Java?</p>