Java File Path Delete deleteDir(File directory)

Here you can find the source of deleteDir(File directory)

Description

Deletes the given directory.

License

Open Source License

Parameter

Parameter Description
directory The directory to be deleted.

Exception

Parameter Description
IOException an exception

Return

true if the directory was deleted; false otherwise.

Declaration

public static boolean deleteDir(File directory) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;

import java.io.IOException;

public class Main {
    /**/* www .j  a  va 2s  .c om*/
     * Deletes the given directory.
     * @param directory The directory to be deleted.
     * @return true if the directory was deleted; false otherwise.
     * @throws IOException 
     */
    public static boolean deleteDir(File directory) throws IOException {
        if (directory.isDirectory()) {
            File[] children = directory.listFiles();
            for (File file : children) {
                boolean success = deleteDir(file);
                if (!success) {
                    return false;
                }
            }
        }
        return directory.delete();
    }
}

Related

  1. deleteDir(File dir)
  2. deleteDir(File dir, boolean deleteRoot)
  3. deleteDir(File dir, boolean deleteSelf)
  4. deleteDir(File dir, int depth, boolean deleteRootDirectory)
  5. deleteDir(File dir, String dirPath)
  6. deleteDir(File directory)
  7. deleteDir(File directory)
  8. deleteDir(File directory)
  9. deleteDir(File directory, boolean removeAll)