Delete Directory Java Program

Sharing is healthy !!

Hi everyone!! You will learn delete directory java program in the following post.

Using delete method we can delete the directory. But the directory should be empty in order to delete it.

If the directory contains a lot of subdirectories and files then we have to use recursive delete in order to delete all subdirectories and files.

Example: Delete Directory Java Program

Delete Directory Java Program

Also Read – Create Directory Java Program

import java.io.*;

public class Delete_Directory {

public static void main(String[] args) {

File fl = new File("C://DeleteDirectory/demo_delete.txt");

boolean bl_Delete = fl.delete();

System.out.println("To check the file deleted True/False: " + bl_Delete);

}
}

Output:

To check the file deleted True/False: true

Sharing is healthy !!