Table of Contents [hide]
In this post, we will see how to delete Directory/Folder which is non empty. You can use java.io.File ‘s delete empy folder but you can not delete it if it is non empty.
There are multiple ways to do it.
When I ran above program, I got following output
There are multiple ways to do it.
- Using java recursion
- Using Apache common IO
Using java recursion:
It is very straight forward to do it. It will iterate through all files in the folder. If it is a file then we can directly delete it but if It finds folder inside it then we again call same method.
Using Apache common IO:
Delete non empty folder is very straight forward. You just need to call FileUtils.deleteDirectory() method.
Java Program:
Was this post helpful?
Let us know if this post was helpful. Feedbacks are monitored on daily basis. Please do provide feedback as that\'s the only way to improve.