Android 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

booleandeleteDir(File dir)
delete Dir
if (dir.isDirectory()) {
    File[] children = dir.listFiles();
    for (File child : children) {
        boolean success = deleteDir(child);
        if (!success) {
            return false;
return dir.delete();
booleandeleteDir(File spec)
Deletes a file or directory.
if (spec.isDirectory()) {
    String[] children = spec.list();
    for (int i = 0; i < children.length; i++) {
        if (!deleteDir(new File(spec, children[i]))) {
            return false;
return spec.delete();
voiddeleteDirContent(File d)
delete Dir Content
if (!d.exists())
    return;
if (!d.isDirectory())
    return;
File[] children = d.listFiles();
for (File c : children) {
    if (c.isDirectory())
        deleteDirContent(c);
...
booleandeleteFile(File f)
delete File
if (f.exists()) {
    if (f.isFile())
        return f.delete();
    else if (f.isDirectory()) {
        File[] files = f.listFiles();
        for (int i = 0; i < files.length; i++) {
            if (!deleteFile(files[i]))
                return false;
...
voiddeleteFile(File f)
Deletes the file
if (!f.exists())
    return;
if (f.isDirectory()) {
    File[] fs = f.listFiles();
    for (File cf : fs) {
        deleteFile(cf);
f.delete();
voiddeleteFile(File f)
delete File
if (!f.exists())
    return;
boolean deleted = f.delete();
if (!deleted)
    throw new IllegalStateException("Could not delete file " + f);
booleandeleteFile(File file)
Convenience method that will call delete() on file and if that fails will call file.deleteOnExit() scheduling the file for deletion upon normal server exit.
boolean result = file.delete();
if (!result) {
    Log.util.warning(8498, file);
    file.deleteOnExit();
return result;
voiddeleteFile(File file)
delete File
if (!file.exists() || !file.isFile()) {
    return;
if (!file.delete()) {
    throw new IllegalStateException("delete file failed: " + file);
voiddeleteFile(File file)
delete File
if (file.exists()) { 
    if (file.isFile()) { 
        file.delete(); 
    } else if (file.isDirectory()) { 
        File files[] = file.listFiles(); 
        for (int i = 0; i < files.length; i++) { 
            deleteFile(files[i]); 
    file.delete();
} else {
    System.out.println("????????????" + '\n');
voiddeleteFile(File file)
delete File
if (file.exists()) {
    file.delete();