Delete an existing file or directory
Delete an existing file or directory
The delete method of file class can be used for deleting a file or directory. The delete method returns true if the file or directory was successfully deleted from the filesystem. If the file object represents a directory, the directory has to be empty for a successful deletion.
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
boolean isDeleted = file.delete();
System.out.println(isDeleted);
}
}
Tags: delete file, File, file class examples, File examples, java.io, java.io.File
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Leave a Reply