file delete() Example
file class delete() example. This example shows you how to use delete() method.
File class delete() example. method generates boolean results after deleting the filr or directory on the specified abstract pathname.path is abstract as it is defined inside the system.method is being called by a File class object.
for deleting a directory , directory chosen to delete should be made empty.
Here is the code:-
/**
* @Program uses delete method to delete files or directories
* directed along the abstract path.
* Delete.java
* Author:-RoseIndia Team
* Date:-30-june-2008
*/
import java.io.*;
public class Delete {
public static void main(String args[]) throws IOException {
File nidhi = new File("/home/mahendra/Desktop/nidhi.wmv");
File bhatia = new File("/home/mahendra/Desktop/bhatia.wmv");
boolean b = nidhi.createNewFile(), c = bhatia.createNewFile();
if (b == true) {
b = nidhi.delete();
if (b == true)
System.out.println("File deleted: " + b);
else
System.out.println("Deletion failed");
}
c = bhatia.createNewFile();
if (c == true) {
c = bhatia.delete();
if (c == true)
System.out.println("File deleted: " + b);
else
System.out.println("Deletion failed");
} else
System.out.println("Abstract path file not found");
}
} |
Output of the program:-
File deleted: true
Abstract path file not found |
|