Java Utililty Methods Delete Tree

List of utility methods to do Delete Tree

Description

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

Method

voiddeleteTree(File dir)
delete Tree
emptyDirectory(dir);
dir.delete();
booleandeleteTree(File dir)
Recursively delete a directory and all of its contents.
if (!dir.exists()) {
    return false;
if (dir.isDirectory()) {
    File[] files = dir.listFiles();
    if (files == null) {
        return false;
    for (File file : files) {
        if (file.isDirectory()) {
            if (!deleteTree(file)) {
                return false;
            continue;
        if (file.isFile()) {
            if (!file.delete()) {
                return false;
            continue;
return dir.delete();
voiddeleteTree(File f)
Recursively delete the contents of a directory, including any subdirectories.
if (null == f) {
    return;
File[] children = f.listFiles();
if (null != children) {
    for (File child : children) {
        deleteTree(child);
f.delete();
booleandeleteTree(File file, boolean check)
Recursively delete a directory and its content.
if (file == null || !file.exists())
    return true;
boolean result = true;
if (check) {
    result = checkDeleteTree(file);
    if (!result)
        return false;
if (file.isDirectory()) {
    File[] files = file.listFiles();
    for (File child : files) {
        result = deleteTree(child, false);
        if (!result)
            break;
if (result)
    result = file.delete();
return result;
voiddeleteTree(final File file)
This method can be used to perform a deep deletion of a directory structure starting at, and including the directory provided.
if (file != null) {
    if (file.isDirectory()) {
        String[] children = file.list();
        for (String child : children) {
            File childFile = new File(file, child);
            deleteTree(childFile);
    file.delete();
booleandelTree(File dir)
Delete a directory and its contents.
emptyDir(dir);
if (dir.delete()) {
    return true;
} else
    return !dir.exists();
booleandelTree(File dir)
del Tree
String[] fileList = dir.list();
String path = dir.getAbsolutePath() + File.separator;
File file;
for (int i = 0; i < fileList.length; ++i) {
    file = new File(path + fileList[i]);
    if (file.isDirectory())
        delTree(file);
    else
...
voiddelTree(File dir, boolean deleteDirItSelf)
File management utilities
if (!dir.exists())
    return;
for (File subFile : dir.listFiles()) {
    if (subFile.isDirectory()) {
        delTree(subFile, true);
    subFile.delete();
if (deleteDirItSelf) {
    dir.delete();
booleandeltree(File directory)
Deletes the given file and everything under it.
if (directory == null || !directory.exists()) {
    return true;
boolean result = true;
if (directory.isFile()) {
    result = directory.delete();
} else {
    File[] list = directory.listFiles();
...
voiddelTree(File directory)
del Tree
if (!directory.isDirectory()) {
    throw new IOException("The file '" + directory + "' is not a directory");
File[] fileArray = directory.listFiles();
if (fileArray == null) {
    throw new IOException("Unable to list the file in the directory : " + directory);
for (int i = 0; i < fileArray.length; i++) {
...