File class deleteOnExit()method example
Requests that the file or directory denoted by this abstract pathname be deleted when the virtual machine terminates.
File class deleteOnExit()method example. This example shows you how to use deleteOnExit()method.This method Requests that the file or directory denoted by this abstract pathname be deleted when the virtual machine terminates.
Here is the code:-
/**
* @Program that Requests that the file or directory denoted by this pathname
be deleted when the virtual machine terminates.
* DeleteOnExit.java
* Author:-RoseIndia Team
* Date:-30-May-2008
*/
import java.io.*;
public class DeleteOnExit {
public static void main(String[] args) throws IOException {
File f = new File("/home/girish/Desktop/g2.txt");
if (f.exists()) {
//The file or directory will be deleted when the virtual machine terminates.
f.deleteOnExit();
} else {
System.out.println("File does not Exists");
}
}
} |
Output of the program:-
compile-single:
run-single: |
|