file deleteOnExit Example
file class deleteOnExit example. This example shows you how to use deleteOnExit method.
File class deleteOnExit example. method is void type therefore does not return anything.it deletes the file or directory on the specified abstract pathname after the termination of JVM(java virtual machine).path is abstract as it is defined inside the system.method is being called with a File class object.
directory should be made empty before attempting it to delete.
Here is the code:-
/**
* @Program uses deleteOnExit method to delete files
* directed with the abstract path after the termination
* of JVM(java virtual machine).
* DeleteOnExit.java
* Author:-RoseIndia Team
* Date:-30-june-2008
*/
import java.io.*;
public class DeleteOnExit {
public static void main(String args[]) {
File root = new File("/home/mahendra/Desktop/matrix.wmv");
if (root.exists()) {
root.deleteOnExit();
System.out.println("File deleted");
} else
System.out.println("Abstract path file not found");
File roots = new File("/home/mahendra/Desktop/baadshah/matrix.wmv");
if (roots.exists()) {
roots.deleteOnExit();
System.out.println("File deleted");
} else
System.out.println("Abstract path file not found");
}
} |
Output of the program:-
File deleted
Abstract path file not found |
|