In this tutorial, I am sharing simple program about How to delete a file in Java.

To delete the file using Java, We have to call the predefined method called delete(). Which is actually belongs to class. This is method will return boolean value such as true If the file is deleted successfully from the file system. It will return false If the file is not exist in the specified path.

package com.dineshkrish.files;
public class FileDeletionExample {
public static void main(String[] args) {
// Defining the File Object
File file = new File("abc.txt");
// Calling the method delete()
boolean flag = file.delete();
if(flag) {
System.out.println("The File is Deleted Successfully!!!!");
} else {
System.out.println("The File is not exist.");


1. Java API Documentation


No responses yet

Leave a Reply

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