How to automatically delete files when jvm terminates

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Filament.io 0 Flares ×

There are situation the program creates many files which are no longer required to be saved in the system once the program exits. A data processing java program may create many files that can be deleted once the program is over. For this File class provides deleteOnExit() method. Calling this method on a file or directory be deleted when the virtual machine terminates.

Deletion will be attempted only for normal termination of the virtual machine and  it is not possible to cancel the request once the deletion is requested. The file will be deleted only when the JVM exits.