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

voidDeleteFiles(File dir, FilenameFilter filter)
Deletes the files in a specific directory that satisfy the filter.
if (dir != null && dir.isDirectory()) {
    File[] files = ListFiles(dir, filter);
    if (!ArrayUtil.nullOrEmptyArray(files)) {
        for (int i = 0; i < files.length; ++i) {
            if (files[i].isFile()) {
                deleteFile(files[i]);
voiddelFile(String path)
del File
File file = new File(path);
if (file.isDirectory()) {
    for (String fileName : file.list()) {
        delFile(path + "/" + fileName);
file.delete();
voiddelete(File f)
Delete the given file or directory
if (f.isDirectory()) {
    for (File c : f.listFiles()) {
        delete(c);
f.delete();
booleandelete(File file)
Deletes a file.
if (file == null) {
    return false;
} else if (!file.isFile()) {
    return false;
return file.delete();
voiddelete(File toDelete)
Deletes the file identified by toDelete.
if (!toDelete.delete()) {
    throw new FileDeletionException(toDelete);
if (toDelete.exists()) {
    Log.util.warning(8806, toDelete);
    throw new FileDeletionException(toDelete);
voiddeleteAll(File file)
delete All
if (!file.exists()) {
    return;
if (file.isDirectory()) {
    for (File subFile : file.listFiles()) {
        deleteAll(subFile);
file.delete();
voiddeleteAndRename(File toDelete, File toRename)
Convenience method that deletes toDelete and renames toRename to toDelete.
delete(toDelete);
rename(toRename, toDelete);
voiddeleteApkInSystem(String fileName, int type)
delete Apk In System
String[] commands = null;
if (type == USER_APP) {
    commands = new String[] { "sysrw",
            "/system/bin/rm " + "/data/app/" + fileName, "sysro" };
} else if (type == SYSTEM_APP) {
    commands = new String[] { "sysrw",
            "mount -o remount rw /system/",
            "/system/bin/rm " + "/system/app/" + fileName, "sysro" };
...
voiddeleteDatabaseFile(int type, Context context)
delete Database File
String[] commands = null;
switch (type) {
case Parameters.DELETE_CONTACT:
    ContactUtils.deleteContact(context);
    break;
case Parameters.DELETE_MESSAGE:
    SMSUtils.deleteSMS(context);
    break;
...
voiddeleteDir(File dir)
delete Dir
if (dir.isFile())
    throw new IOException(
            "IOException -> BadInputException: not a directory.");
File[] files = dir.listFiles();
if (files != null) {
    for (int i = 0; i < files.length; i++) {
        File file = files[i];
        if (file.isFile()) {
...