Java Utililty Methods File Delete

List of utility methods to do File Delete

Description

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

Method

voiddelete(File f)
Recursive delete.
if (!f.exists())
    return;
if (f.isDirectory()) {
    File[] kids = list(f);
    for (int i = 0; kids != null && i < kids.length; ++i)
        delete(kids[i]);
if (!f.delete())
...
booleandelete(File f)
delete
if (f.isFile())
    return f.delete();
else if (f.isDirectory()) {
    boolean b = clearDir(f);
    b &= f.delete();
    return b;
} else
    return false;
...
voiddelete(File f)
delete
if (f.isDirectory()) {
    for (File c : f.listFiles()) {
        delete(c);
if (!f.delete()) {
    throw new FileNotFoundException("Failed to delete file: " + f.getAbsolutePath());
voiddelete(File f)
delete
if (f.exists()) {
    if (f.isDirectory())
        for (File f2 : listAllFiles(f))
            delete(f2);
    f.delete();
booleandelete(File f)
Delete the file.
if (f == null) {
    return true;
return f.delete();
booleandelete(File f)
Deletes the file/directory recursively and quietly.
if (f == null) {
    return false;
if (f.exists()) {
    if (f.isDirectory()) {
        for (File ff : f.listFiles()) {
            if (ff.isDirectory()) {
                delete(ff);
...
voiddelete(File f)
delete
if (f.isDirectory()) {
    for (File c : f.listFiles())
        delete(c);
if (!f.delete())
    System.out.println(
            "Failed to delete file: " + f + " file does " + f.exists() + " exists (false = not..)");
booleandelete(File f)
Accommodate Windows bug encountered in both Sun and IBM JDKs.
if (!f.delete()) {
    if (System.getProperty("os.name").toLowerCase().indexOf("windows") > -1) {
        System.gc();
    try {
        Thread.sleep(10);
        return f.delete();
    } catch (InterruptedException ex) {
...
booleandelete(File f)
delete
return (f != null) ? f.delete() : false;
booleandelete(File f)
Deletes the given file and, if it is a directory, delete all its sub-directories and sub-files.
if (f.isFile())
    return f.delete();
else if (f.isDirectory()) {
    boolean b = clearDir(f);
    b &= f.delete();
    return b;
} else
    return false;
...