When are Java temporary files deleted?

The file won’t be deleted automatically, from the JavaDoc:

This method provides only part of a temporary-file facility. To
arrange for a file created by this method to be deleted automatically,
use the deleteOnExit() method.

So you have to explicitly call deleteOnExit():

Requests that the file or directory denoted by this abstract pathname
be deleted when the virtual machine terminates.

Leave a Comment

tech