Java Utililty Methods Delete File Recursively

List of utility methods to do Delete File Recursively

Description

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

Method

voiddeleteRecursive(File f)
Delete directory or file recursively
if (f.isDirectory())
    for (File c : f.listFiles())
        deleteRecursive(c);
f.delete();
voiddeleteRecursive(File file)
delete Recursive
if (file.exists()) {
    if (file.isDirectory()) {
        for (File f : file.listFiles()) {
            deleteRecursive(f);
    boolean deleted = file.delete();
    if (deleted)
...
voiddeleteRecursive(File file)
Think "deltree" or "rm -r".
if (file.isDirectory()) {
    for (File f : file.listFiles())
        deleteRecursive(f);
file.delete();
voiddeleteRecursive(File file)
Deletes a directory or file

Taken from http://forum.java.sun.com/thread.jspa?threadID=470197&messageID=2169110

Author: jfbriere

if (file.isDirectory()) {
    File[] fileArray = file.listFiles();
    if (fileArray != null) {
        for (File aFileArray : fileArray) {
            deleteRecursive(aFileArray);
if (!file.delete()) {
    System.err.println("Cannot delete file");
voiddeleteRecursive(File file)
Recursively deletes a file/folder and all its subcontent.
List<File> exploreQueue = new ArrayList<File>();
List<File> exploreQueue2 = new ArrayList<File>();
List<File> deleteQueue = new ArrayList<File>();
exploreQueue.add(file);
while (!exploreQueue.isEmpty()) {
    deleteQueue.addAll(0, exploreQueue);
    for (File toExplore : exploreQueue) {
        if (toExplore.isDirectory()) {
...
voiddeleteRecursive(File file)
delete Recursive
if (file.isDirectory()) {
    File[] files = file.listFiles();
    if (files != null) {
        for (File f : files) {
            deleteRecursive(f);
        if (!file.delete()) {
            System.out.println("Could not delete folder " + file);
...
voiddeleteRecursive(File file)
Recursively deletes the provided file, being careful to not follow symbolic links (but there are still unavoidable race conditions).
if (file.isDirectory()
        && file.getCanonicalPath().equals(file.getAbsolutePath())) {
    File afile[] = file.listFiles();
    if (afile != null)
        for (File f : afile)
            deleteRecursive(f);
delete(file);
...
voiddeleteRecursive(File file)
delete Recursive
Set<File> visited = new HashSet<File>();
deleteRecursive(file, visited);
booleandeleteRecursive(File file)
Recursively delete possibly non-empty directory or file.
if (!file.exists()) {
    return false;
boolean rc = true;
if (file.isDirectory()) {
    File[] fileList = file.listFiles();
    for (int i = 0; i < fileList.length; i++) {
        rc &= deleteRecursive(fileList[i]);
...
booleandeleteRecursive(File root)
Do rm -rf
if (!!!root.exists())
    return false;
else if (root.isFile())
    return root.delete();
else {
    boolean result = true;
    for (File f : root.listFiles()) {
        result = deleteRecursive(f) && result;
...