Here you can find the source of deleteDirRecursive(String dirPath)
public static boolean deleteDirRecursive(String dirPath)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.util.ArrayList; import java.util.Collection; import java.util.List; public class Main { public static boolean deleteDirRecursive(String dirPath) { File dir = new File(dirPath); if (dir.isDirectory()) { File[] children = dir.listFiles(); for (int i = 0; i < children.length; i++) { boolean success = deleteDirRecursive(children[i].getAbsolutePath()); if (!success) { return false; }/*w ww .j a v a2 s . c o m*/ } } return dir.delete(); } public static Collection<File> listFiles(String rootDor) { File root = new File(rootDor); List<File> files = new ArrayList<File>(); listFiles(files, root); return files; } private static void listFiles(List<File> files, File dir) { File[] listFiles = dir.listFiles(); for (File f : listFiles) { if (f.isFile()) { files.add(f); } else if (f.isDirectory()) { listFiles(files, f); } } } }