Java Delete Directory deleteDirectory(File root)

Here you can find the source of deleteDirectory(File root)

Description

delete Directory

License

Apache License

Declaration

public static void deleteDirectory(File root) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.*;

public class Main {

    public static void deleteDirectory(File root) {
        if (root == null || !root.exists()) {
            return;
        }//from   w ww . jav  a 2 s.  c om
        if (root.isFile()) {
            root.delete();
        } else if (root.isDirectory()) {
            File[] children = root.listFiles();
            if (children != null) {
                for (File child : children) {
                    if (child.isFile()) {
                        child.delete();
                    } else if (child.isDirectory()) {
                        deleteDirectory(child);
                    }
                }
            }
            root.delete();
        }
    }
}

Related

  1. deleteDirectory(File file)
  2. deleteDirectory(File file)
  3. deleteDirectory(File file)
  4. deleteDirectory(File file)
  5. deleteDirectory(File fileOrDir)
  6. deleteDirectory(File root)
  7. deleteDirectory(File root)
  8. deleteDirectory(File sourceDirectory, FilenameFilter filter, boolean recursive, boolean deleteItself)
  9. deleteDirectory(final File dir)