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 src)
Deletes the file, recursively scanning sub-directories if its a directory.
clearDirectory(src);
if (src.exists() && !src.delete()) {
    throw new IOException("Could not delete: " + src);
voiddeleteRecursive(File src, List excludes)
delete Recursive
if (!src.exists())
    throw new IOException("File/directory does not exist: " + src);
if (excludes == null || !excludes.contains(src)) {
    if (src.isFile()) {
        if (!src.delete())
            throw new IOException("Cannot delete file: " + src);
    } else {
        for (File srcFile : src.listFiles()) {
...
voiddeleteRecursive(File toDelete)
delete Recursive
if (toDelete.isFile()) {
    toDelete.delete();
} else if (toDelete.isDirectory()) {
    for (File f : toDelete.listFiles()) {
        deleteRecursive(f);
voiddeleteRecursive(File toDelete)
This method acts much like bash's "rm -rf $file" command.
for (File sub : toDelete.listFiles()) {
    if (sub.isDirectory()) {
        deleteRecursive(sub);
    } else {
        if (!sub.delete()) {
            throw new IOException();
booleandeleteRecursive(final File dir)
delete Recursive
boolean ret = true;
if (dir.isDirectory()) {
    final String[] entries = dir.list();
    for (final String entry : entries) {
        final File actFile = new File(dir.getPath(), entry);
        ret &= deleteRecursive(actFile);
return (ret & dir.delete());
booleandeleteRecursive(final File file)
Deletes a file or directory.
boolean result = true;
if (file.isDirectory()) {
    for (final File inner : file.listFiles()) {
        result &= deleteRecursive(inner);
return result & file.delete();
booleandeleteRecursive(final File file)
delete Recursive
boolean ok = true;
if (file.exists()) {
    if (file.isDirectory()) {
        for (File child : file.listFiles())
            ok &= deleteRecursive(child);
    ok &= file.delete();
return ok;
voiddeleteRecursive(final File file)
Rekursives l?schen von Dateien und Verzeichnissen
if (file == null)
    return;
if (file.isDirectory()) {
    final File[] files = file.listFiles();
    for (int i = 0; i < files.length; i++)
        deleteRecursive(files[i]);
file.delete();
...
booleandeleteRecursive(final File file, final boolean collect)
delete Recursive
boolean result = true;
if (collect && isWindows()) {
    System.gc(); 
File[] children = file.listFiles();
if (children != null) {
    for (File sf : children) {
        if (sf.isDirectory()) {
...
booleandeleteRecursiveDir(File directory)
Delete the directory and its subdirs associated with the File as path if empty
if (directory == null) {
    return true;
boolean retour = true;
if (!directory.exists()) {
    return true;
if (!directory.isDirectory()) {
...