what is the difference between delete() and deleteOnExit() methods in java.io.File class in Java?
To delete a file in Java, we can use the delete() method from Files class. We can also use the delete() method on an object which is an instance of the File class.
In Java, we can delete a file by using the File. delete() method of File class. The delete() method deletes the file or directory denoted by the abstract pathname. If the pathname is a directory, that directory must be empty to delete.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With