1. Introduction
The deleteOnExit() method qualifies the specified file or directory for deletion when the virtual machine terminates. Removal is carried out in reverse order to registering. The delete operation will be attempted only for normal termination of the JVM.
2. Method signature
Parameters:
- method does not take any parameter
Returns
- method does not return anything
Throws
- SecurityException - when SecurityManager denies delete access to the file
3. Examples
3.1. Remove file /tmp/frontbackend.txt
when JVM terminates
No output.
4. Conclusion
In this article, we presented File.deleteOnExit()
the method that deletes a file when Java Virtual Machine terminates. Normally this operation happens when we restart the application server or our program stopped. We use this method to eliminate cluttering the operating system and free up unused disk storage resources.
{{ 'Comments (%count%)' | trans {count:count} }}
{{ 'Comments are closed.' | trans }}