Java Utililty Methods Delete Directory

List of utility methods to do Delete Directory

Description

The list of methods to do Delete Directory are organized into topic(s).

Method

booleandeleteDirectory(File directory)
delete Directory
if (directory.isDirectory()) {
    File[] fileList = directory.listFiles();
    if (fileList != null) {
        for (File file : fileList) {
            deleteDirectory(file);
return directory.delete();
booleandeleteDirectory(File directory)
Recursively deletes a directory and everything under it.
boolean globalSuccess = true;
boolean success;
if (directory.isDirectory()) {
    String[] children = directory.list();
    for (int i = 0; i < children.length; i++) {
        success = deleteDirectory(new File(directory, children[i]));
        globalSuccess = success && globalSuccess;
success = directory.delete();
globalSuccess = success && globalSuccess;
return globalSuccess;
voiddeleteDirectory(File directory)
delete directory
cleanDirectory(directory);
directory.delete();
voiddeleteDirectory(File directory)
delete Directory
if (directory.getPath().length() <= 4) {
    throw new IllegalArgumentException("Path length is too short");
for (File file : directory.listFiles()) {
    if (file.isDirectory()) {
        deleteDirectory(file);
    } else {
        boolean success = file.delete();
...
voiddeleteDirectory(File directory)
Deletes a directory recursively.
if (!directory.exists()) {
    return;
cleanDirectory(directory);
if (!directory.delete()) {
    throw new IOException("Unable to delete directory: " + directory);
booleandeleteDirectory(File directory)
Delete one directory include sub-dirs and sub-files.
if (!directory.exists())
    return true;
if (directory.isFile()) {
    return directory.delete();
File[] files = directory.listFiles();
boolean finalSuccess = true;
if (files != null) {
...
booleandeleteDirectory(File directory)
http://stackoverflow.com/questions/3775694/deleting-folder-from-java
if (directory.exists()) {
    File[] files = directory.listFiles();
    if (null != files) {
        for (int i = 0; i < files.length; i++) {
            if (files[i].isDirectory()) {
                deleteDirectory(files[i]);
            } else {
                if (!files[i].delete())
...
booleandeleteDirectory(File directory)
Delete the given directory along with all files and sub directories.
if (directory.isDirectory()) {
    for (File f : directory.listFiles()) {
        boolean success = deleteDirectory(f);
        if (!success) {
            return false;
return directory.delete();
voiddeleteDirectory(File directory)
delete Directory
if (!directory.exists())
    return;
cleanDirectory(directory);
if (!directory.delete()) {
    String message = "Unable to delete directory " + directory + ".";
    throw new IOException(message);
} else {
    return;
...
voiddeleteDirectory(File directory)
Deletes directory and its content
for (File file : directory.listFiles()) {
    if (file.isDirectory())
        deleteDirectory(file);
    else
        file.delete();
directory.delete();