I'm looking for a safe way to create a temp file in Java. By safe, I mean the following:
- 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)
- File should be private, even under potential race conditions (e.g. another user tries to chmod file at high rate)
- I can tell it to delete the file, without me having to do a generic delete, and risk deleting the wrong file
- Ideally, should ensure file is deleted, even if exception is thrown before I get the chance to
- File should default to a sane location (e.g. the JVM specified tmp dir, defaulting to the system temp dir)