Here you can find the source of removeDirectory(String pathToDir)
public static boolean removeDirectory(String pathToDir)
//package com.java2s; import java.io.File; public class Main { /** Remove directory and all its sub-resources with specified path */ public static boolean removeDirectory(String pathToDir) { return deleteRecursive(new File(pathToDir)); }/*from w ww. j av a 2s .co m*/ /** * Remove specified file or directory. * * @param fileOrDirectory * the file or directory to cancel * @return <code>true</code> if specified File was deleted and <code>false</code> otherwise */ public static boolean deleteRecursive(File fileOrDirectory) { if (fileOrDirectory.isDirectory()) { File[] list = fileOrDirectory.listFiles(); if (list == null) { return false; } for (File f : list) { if (!deleteRecursive(f)) { return false; } } } return !fileOrDirectory.exists() || fileOrDirectory.delete(); } /** * Remove specified file or directory. * * @param fileOrDirectory * the file or directory to cancel * @param followLinks * are symbolic links followed or not? * @return <code>true</code> if specified File was deleted and <code>false</code> otherwise */ public static boolean deleteRecursive(File fileOrDirectory, boolean followLinks) { if (fileOrDirectory.isDirectory()) { // If fileOrDirectory represents a symbolic link to a folder, // do not read a target folder content. Just remove this symbolic link. if (!followLinks && java.nio.file.Files.isSymbolicLink(fileOrDirectory.toPath())) { return !fileOrDirectory.exists() || fileOrDirectory.delete(); } File[] list = fileOrDirectory.listFiles(); if (list == null) { return false; } for (File f : list) { if (!deleteRecursive(f, followLinks)) { return false; } } } return !fileOrDirectory.exists() || fileOrDirectory.delete(); } }