Java Utililty Methods File Path Delete

List of utility methods to do File Path Delete

Description

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

Method

booleandeletePath(File path)
Delete all files and sub-folders of the specified path, and then the specified path itself.
if (path == null)
    throw new IllegalArgumentException("Null path in FileUtil.deletePath()");
boolean ok = true;
try {
    File[] files = path.listFiles();
    for (int i = 0; i < files.length && ok; i++) {
        if (files[i].exists() && files[i].isDirectory())
            ok = deletePath(files[i]);
...
voiddeletePath(final File path)
delete Path
deletePathAndRetry(path, 3);
booleandeletePathRecursive(File path)
delete Path Recursive
if (path.isDirectory()) {
    for (File file : path.listFiles()) {
        if (!deletePathRecursive(file))
            return false;
return path.delete();
booleandeleteQuietly(Object path)
delete Quietly
return deleteQuietly(path, false);
voiddeleteRecursive(File path)
Delete a directory and its contents recursively
File[] c = path.listFiles();
for (File file : c) {
    if (file.isDirectory()) {
        deleteRecursive(file);
        file.delete();
    } else {
        file.delete();
path.delete();
booleandeleteRecursive(File path)
By default File#delete fails for non-empty directories, it works like "rm".
if (!path.exists()) {
    throw new FileNotFoundException(path.getAbsolutePath());
boolean ret = true;
if (path.isDirectory()) {
    for (File f : path.listFiles()) {
        ret = ret && deleteRecursive(f);
return ret && path.delete();
booleandeleteRecursive(File path)
delete Recursive
if (path.exists()) {
    boolean ret = true;
    if (path.isDirectory()) {
        for (File f : path.listFiles()) {
            ret = ret && deleteRecursive(f);
    return ret && path.delete();
...
booleandeleteRecursive(File path)
delete Recursive
if (path != null && path.exists() && path.isDirectory()) {
    File[] files = path.listFiles();
    for (File f : files) {
        if (f.isDirectory()) {
            deleteRecursive(f);
        } else {
            f.delete();
if (path != null) {
    boolean successful = path.delete();
    return successful;
} else {
    return false;
booleandeleteRecursive(File path)
Remove a file/directory.
boolean deleteSuccessful = false;
if (!exists(path)) {
    return deleteSuccessful;
boolean ret = true;
if (path.isDirectory()) {
    for (File f : path.listFiles()) {
        ret = ret && deleteRecursive(f);
...
booleandeleteRecursive(File path)
This function will recursivly delete directories and files.
if ((path.exists()) && (path.isDirectory())) {
    File[] files = path.listFiles();
    if (files != null) {
        for (int i = 0; i < files.length; i++) {
            if (files[i].isDirectory()) {
                deleteRecursive(files[i]);
            } else {
                files[i].delete();
...