Here you can find the source of recursiveDelete(File fileOrDir)
Parameter | Description |
---|---|
fileOrDir | the file or dir to delete |
public static boolean recursiveDelete(File fileOrDir)
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(); } }