How do I delete directory recursively?

Using the FileUtils.deleteDirectory() method can help to simplify the process of deleting directory and everything below it recursively.




public class DeleteDirectory {
    public static void main(String[] args) {
        try {
            File directory = new File("/home/foobar/Temp/Data");

            // Deletes a directory recursively. When deletion process is fail an
            // IOException is thrown and that's why we catch the exception.
        } catch (IOException e) {

Maven Dependencies

<!-- -->

Wayan Saryada

Founder at Kode Java Org
I am a programmer, a runner, a recreational diver, currently live in the island of Bali, Indonesia. Mostly programming in Java, Spring Framework, Hibernate / JPA. You can support my works by donating here. Thank you 🥳

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.