Deleting a file

The source code for deleting a file is shown below.Here I am trying to delete the file if it is not a directory.


* User: Bijoy
* Date: 6/25/12
* Time: 9:18 PM
public class FileDelete {
public static void main(String[] args) {
try {
File file = new File("E:/temp/test.txt");
if (!file.isDirectory()) {
} else {
System.out.println("It is a directory");
} catch (Exception e) {

Remember, the specified file should be existing. If it is not existing please create the file in the correct path.

One thought on “Deleting a file

Leave a Reply

Your email address will not be published. Required fields are marked *