Skip to content
Advertisement

File.createTempFile check if file exists?

If I use this method, and by chance there is a temporary file with the same name, the file is overwritten? I’m talking about an application that will generate many temporary files, for a long time.

Advertisement

Answer

From the JavaDoc on createTempFile (here) on the line labeled 2,

Neither this method nor any of its variants will return the same abstract pathname again in the current invocation of the virtual machine.

Edit

And the Returns section says

An abstract pathname denoting a newly-created empty file

And, it further states

Creates a new empty file in the specified directory, using the given prefix and suffix strings to generate its name. If this method returns successfully then it is guaranteed that: The file denoted by the returned abstract pathname did not exist before this method was invoked

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement