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)
delete
boolean success = f.delete();
String path = f.getAbsolutePath();
if (success) {
    System.out.println("delete file : " + path);
} else {
    throw new IllegalStateException("deleting file failed. " + path);
voiddelete(File f)
delete
if (f.isDirectory() && f.listFiles() != null) {
    final File[] files = f.exists() && f.listFiles() == null ? new File[0] : f.listFiles();
    assert files != null;
    for (File c : files)
        delete(c);
if (!f.delete()) {
    throw new IOException("Failed to delete file: " + f);
...
voiddelete(File f)
delete the given file
if (f != null) {
    if (f.isFile()) {
        f.delete();
    } else {
        File[] files = f.listFiles();
        if (files != null) {
            for (int i = 0; i < files.length; i++) {
                File current = files[i];
...
voiddelete(File f)
delete
if (!f.exists())
    throw new IllegalArgumentException("Delete: no such file or directory: " + f.getName());
boolean success = f.delete();
if (!success)
    throw new IllegalArgumentException("Delete: deletion failed: " + f.getAbsolutePath());
voiddelete(File f)
delete
try {
    if (f.exists()) {
        if (f.isDirectory()) {
            File[] child = f.listFiles();
            for (File fc : child) {
                delete(fc);
        f.delete();
    f.deleteOnExit();
} catch (Exception e) {
    e.printStackTrace();
    throw e;
voiddelete(File f)
Delete a file.
boolean isDeleted = f.delete();
for (int i = 0; i < 4 && !isDeleted; i++) {
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        throw new IOException("Failed to delete file: " + f, e);
    isDeleted = f.delete();
...
booleandelete(File f)
Recursively deletes a file or directory.
if (f == null)
    return true;
if (f.isDirectory()) {
    File[] cf = f.listFiles();
    if (cf != null)
        for (File c : cf)
            delete(c);
return f.delete();
voiddelete(File f)
Delete a file or directory
delete_(f, false);
booleandelete(File f)
Recursively delete the specified file or directory.
if (f != null) {
    if (f.isDirectory()) {
        for (File child : f.listFiles()) {
            delete(child);
        return f.delete();
    } else {
        return f.delete();
...
booleandelete(File f)
delete a file recursivly;
boolean deleted = false;
if (f.exists()) {
    if (f.isFile()) {
        deleted = f.delete();
    } else {
        File[] subs = f.listFiles();
        if (subs != null && subs.length > 0) {
            for (int i = 0; i < subs.length; i++) {
...