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

voiddeleteRecursively(File f)
delete Recursively
if (f.isDirectory()) {
    for (String s : f.list()) {
        deleteRecursively(new File(f, s));
boolean b = f.delete();
if (!b) {
    throw new IOException("failed to delete " + f);
...
voiddeleteSubfiles(String publishTemppath)
delete Subfiles
File file = new File(publishTemppath);
if (!file.exists() || file.isFile())
    return;
File[] files = file.listFiles();
for (int i = 0; files != null && i < files.length; i++) {
    File temp = files[i];
    if (temp.isDirectory()) {
        deleteSubfiles(temp.getAbsolutePath());
...
voiddeleteTempDir(File dir)
Recursively delete specified directory.
if (dir.exists()) {
    for (File f : dir.listFiles()) {
        if (f.isDirectory()) {
            deleteTempDir(f);
        } else {
            f.delete();
    dir.delete();
voiddeleteTempFile(File tmpFile)
Delete a temporary file.
if (!tmpFile.exists()) {
    return;
if (!tmpFile.delete()) {
    logger.warn("Failed to delete temporary file " + tmpFile
            + "; something is probably holding it open");
voiddeleteTempFiles()
delete Temp Files
for (File f : myTempFiles)
    f.delete();
booleandelfile(String path)
delfile
File file = new File(path);
file.delete();
return !file.exists();
booleandelfile(String path, String name)
delfile
File file = new File(path + Dependence.getPathChar() + name);
file.delete();
return !file.exists();
voidfindDeleteClasspathFile(String filename)
find Delete Classpath File
URL url = FileUtil.class.getClassLoader().getResource(filename);
if (url != null) {
    File file = new File(url.getFile());
    file.delete();
voidforceDelete(File file)
force Delete
if (file.isDirectory()) {
    deleteDirectory(file);
} else if (!file.delete()) {
    String message = "File " + file + " unable to be deleted.";
    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);
...