use of deleteOnExit() method in java

Vishal Chugh picture Vishal Chugh · Sep 25, 2013 · Viewed 28.5k times · Source

what is the difference between delete() and deleteOnExit() methods in java.io.File class in Java?

Answer

Barny picture Barny · Mar 30, 2016

delete() will delete the file at once, while deleteOnExit() will not delete the file, when you call it. Instead the file is deleted, when the program ends or more precise the virtual machine terminates.

In case the virtual machines terminates not regulary, deleteOnExit() has no effect.