Delete a file or directory when JVM terminates.
The deleteOnExit method of file class can be used for deleting a file or directory when JVM terminates.
package io;
import java.io.File;
/**
* File class examples
*
* Contains different operations of java.io.File class.
*/
public class FileExample {
public static void main(String[] args){
File file = new File("d:\\temp\\test1.txt");
// Delete the file or directory when JVM terminates
file.deleteOnExit();
}
}