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

voiddeleteR(File dir)
delete R
deleteR(dir, true);
voiddeleteRec(File f)
Delete a file and all subfiles.
if (f.isDirectory()) {
    File[] kids = f.listFiles();
    if (kids == null) {
        throw new IOException("List " + f);
    for (File kid : kids) {
        deleteRec(kid);
if (!f.delete()) {
    throw new IOException("Delete " + f);
booleandeleteRecursive(File dir)
Loescht ein Verzeichnis rekursiv.
File candir = dir.getCanonicalFile();
if (!candir.equals(dir.getAbsoluteFile()))
    return false;
File[] files = candir.listFiles();
if (files != null) {
    for (int i = 0; i < files.length; ++i) {
        boolean deleted = files[i].delete();
        if (!deleted) {
...
booleandeleteRecursive(File dir)
Deletes the content of a directory completely.
if (dir.isFile() || (dir.listFiles().length == 0)) {
    dir.delete();
    return true;
for (File f : dir.listFiles()) {
    deleteRecursive(f);
return dir.delete();
...
booleandeleteRecursive(File dir)
Recursively deletes an entire directory hierarchy.
if (!dir.exists())
    return (true);
boolean success = true;
String files[] = dir.list();
if (files != null) {
    for (int i = 0; i < files.length; i++) {
        File file = new File(dir, files[i]);
        if (file.isDirectory())
...
voiddeleteRecursive(File dir)
delete Recursive
if (!dir.exists())
    return;
deleteContentsRecursive(dir);
if (!dir.delete())
    throw new IOException("Unable to delete " + dir);
booleandeleteRecursive(File dir)
Deletes everything under a directory (including subdirectories)
if (!dir.exists()) {
    return true;
File tempFile;
File[] fileList = dir.listFiles();
int fileListLength = fileList.length;
int index;
boolean result = false;
...
voiddeleteRecursive(File f)
Deletes all the file/directory and all of its children
if (f.isDirectory()) {
    for (File c : f.listFiles())
        deleteRecursive(c);
if (!f.delete())
    throw new RuntimeException("Failed to delete file: " + f);
voiddeleteRecursive(File f)
delete Recursive
if (f.isDirectory()) {
    File[] entries = f.listFiles();
    for (int i = 0; i < entries.length; i++) {
        deleteRecursive(entries[i]);
f.delete();
voiddeleteRecursive(File f)
Recursively delete a directory / file For safety this method only deletes files created under the workspace
if (!f.getAbsolutePath()
        .startsWith(ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile().getAbsolutePath())) {
    throw new IllegalArgumentException("File must exist within the workspace!");
if (f.isDirectory()) {
    for (File f1 : f.listFiles()) {
        deleteRecursive(f1);
f.delete();