Android File Delete recursiveDelete(File fileOrDir)

Here you can find the source of recursiveDelete(File fileOrDir)

Description

Recursively delete file or directory

License

Open Source License

Parameter

Parameter Description
fileOrDir the file or dir to delete

Return

true if all files are successfully deleted

Declaration

public static boolean recursiveDelete(File fileOrDir) 

Method Source Code

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.net.URL;
import java.util.UUID;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import net.sf.json.JSON;
import net.sf.json.JSONObject;
import org.apache.log4j.Logger;

public class Main{
    private static Logger l = Logger.getLogger(FileUtil.class);
    /**/*from   w ww. j a v a2s .c  o  m*/
     * Recursively delete file or directory
     *
     * @param fileOrDir the file or dir to delete
     * @return true if all files are successfully deleted
     */
    public static boolean recursiveDelete(File fileOrDir) {
        l.debug("Deleting " + fileOrDir + " recursively.");
        if (fileOrDir.isDirectory()) {
            // recursively delete contents
            for (File innerFile : fileOrDir.listFiles()) {
                if (!recursiveDelete(innerFile)) {
                    return false;
                }
            }
        }
        l.debug("Deleted" + fileOrDir + " recursively.");
        return fileOrDir.delete();
    }
}

Related

  1. findDeleteClasspathFile(String filename)
  2. forceDelete(File file)
  3. forceDelete(File file)
  4. forceDelete(String file)
  5. forceDelete(final File file)
  6. recursiveDelete(File path)
  7. removeableFile(File folder, String fileName)
  8. renameFile(String strSrc, String strDest, boolean deleteIfExist)
  9. safelyDeleteFile(File filePath)