File class delete()method example
Deletes the file or directory denoted by this abstract pathname.
File class delete()method example. This example shows you how to use delete()method.This method Deletes the file or directory denoted by this abstract pathname.
Here is the code:-
/**
* @Program that Deletes the file or directory denoted by this abstract pathname.
* Delete.java
* Author:-RoseIndia Team
* Date:-30-May-2008
*/
import java.io.*;
public class Delete {
public static void main(String[] args) {
File f = new File("/home/girish/Desktop/g1.txt");
if (f.exists()) {
if (f.delete()) {
//Deletes the file or directory denoted by this abstract pathname.
System.out.println(f.getAbsolutePath() + " File deleted Successfully");
} else {
System.out.println("File Cannot be deleted");
}
} else {
System.out.println("File does not exists");
}
}
} |
Output of the program:-
| /home/girish/Desktop/g1.txt File deleted Successfully |
|