Java Utililty Methods Force Delete

List of utility methods to do Force Delete

Description

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

Method

voidforceDelete(File f)
force Delete
if (f.isDirectory()) {
    File[] sub = f.listFiles();
    for (int i = 0; i < sub.length; i++) {
        forceDelete(sub[i]);
f.delete();
voidforceDelete(File f)
force Delete
if (f.isDirectory()) {
    String[] children = f.list();
    for (int i = 0; i < children.length; i++) {
        forceDelete(new File(f, children[i]));
if (f.exists() && !f.delete()) {
    throw new IOException("Failed to delete file : " + f.getAbsolutePath());
...
booleanforceDelete(File file)
Recursively delete file
if (!file.exists()) {
    return true;
if (file.isDirectory()) {
    File[] files = file.listFiles();
    if (files != null) {
        for (int i = 0; i < files.length; i++) {
            if (!forceDelete(files[i])) {
...
booleanforceDelete(File file)
A "brute force" method to delete a file that might be in use by another thread or application.
if (!file.exists()) {
    return true;
if (file.isDirectory()) {
    return file.delete();
for (int i = 1; i < 20; i++) {
    if (file.delete()) {
...
voidforceDelete(File file)
force Delete
if (file.isDirectory()) {
    File[] files = file.listFiles();
    for (File child : files) {
        forceDelete(child);
    deleteFile(file);
} else {
    deleteFile(file);
...
voidforceDelete(File file)
Deletes a file.
if (file.isDirectory()) {
    deleteDirectory(file);
} else {
    boolean filePresent = file.exists();
    if (!file.delete()) {
        if (!filePresent) {
            throw new FileNotFoundException("File does not exist: " + file);
        String message = "Unable to delete file: " + file;
        throw new IOException(message);
voidforceDelete(File file)
Deletes a file.
if (file.isDirectory()) {
    deleteDirectory(file);
} else {
    boolean filePresent = file.exists();
    if (!file.delete()) {
        if (!filePresent) {
            throw new FileNotFoundException("File does not exist: " + file);
        throw new IOException("Unable to delete file: " + file);
voidforceDelete(File file)
force Delete
if (file.isDirectory()) {
    deleteDirectory(file);
} else {
    if (!file.exists())
        throw new FileNotFoundException("File does not exist: " + file);
    if (!file.delete()) {
        String message = "Unable to delete file: " + file;
        throw new IOException(message);
...
voidforceDelete(File file)
Deletes a file.
if (file.isDirectory()) {
    deleteDirectory(file);
} else {
    boolean filePresent = file.exists();
    if (!file.delete()) {
        if (!filePresent) {
            throw new FileNotFoundException("File does not exist: " + file);
        String message = "Unable to delete file: " + file;
        throw new IOException(message);
voidforceDelete(File file)
force Delete
if (file.isDirectory()) {
    deleteDirectory(file);
} else {
    boolean filePresent = file.exists();
    if (!file.delete()) {
        if (!filePresent) {
            throw new FileNotFoundException("File does not exist: " + file);
        String message = "Unable to delete file: " + file;
        throw new IOException(message);