Here you can find the source of deleteDirectory(final String directoryPath)
public static boolean deleteDirectory(final String directoryPath)
//package com.java2s; // Licensed under the MIT license. See License.txt in the repository root. import java.io.File; import java.io.FileFilter; public class Main { public static boolean deleteDirectory(final String directoryPath) { return deleteDirectory(new File(directoryPath)); }// w ww . j a v a 2 s . c om public static boolean deleteDirectory(final File directory) { if (!directory.exists() || !directory.isDirectory()) { return false; } /* Depth-first directory traversal */ final File[] subdirectories = directory.listFiles(new FileFilter() { @Override public boolean accept(final File file) { return file.isDirectory(); } }); for (final File subdirectory : subdirectories) { if (!deleteDirectory(subdirectory)) { return false; } } final File[] files = directory.listFiles(new FileFilter() { @Override public boolean accept(final File file) { return file.isFile(); } }); for (final File file : files) { if (!file.delete()) { return false; } } return directory.delete(); } }