How to delete folder and sub folders using Java

How to delete folder and sub folders using Java:
Deleting an empty directory is easy in Java, just use delete() method of java.io.File class, but deleting a directory with files is unfortunately not easy.

How to delete folder and sub folders using Java

You just can’t delete a folder if it contains files or sub folders. Calling delete() method on a File instance representing a non empty directory will just return false without removing the directory.

Program Output

Files deleted……..

If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.

Recommended Posts:


Editorial Staff

Editorial Staff at FreeWebMentor is a team of professional developers.

Comments and Discussions

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