title: What is a safe way to create a Temp file in Java?
body: <p>I'm looking for a <strong>safe</strong> way to create a temp file in Java.  By safe, I mean the following:</p>
  
  <ul>
  <li>Name should be unique, even under potential race conditions (e.g. another Thread calls the same func at the same time, or another process runs this code simultaneously)</li>
  <li>File should be private, even under potential race conditions (e.g. another user tries to chmod file at high rate)</li>
  <li>I can tell it to delete the file, without me having to do a generic delete, and risk deleting the wrong file</li>
  <li>Ideally, should ensure file is deleted, even if exception is thrown before I get the chance to</li>
  <li>File should default to a sane location (e.g. the JVM specified tmp dir, defaulting to the system temp dir)</li>
  </ul>