Java tutorial
//package com.java2s; import java.io.File; public class Main { /** * Removes the directory. * * @param directory * the directory * @return true, if successful */ public static boolean removeDirectory(String directory) { if (directory != null && directory.length() > 0) { return removeDirectory(new File(directory)); } return false; } /** * Removes the directory. * * @param directory * the directory * @return true, if successful */ public static boolean removeDirectory(File directory) { if (directory == null) { return false; } if (!directory.exists()) { return true; } if (directory.isDirectory()) { final String[] list = directory.list(); // Some JVMs return null for File.list() when the // directory is empty. if (list != null) { for (final String element : list) { final File entry = new File(directory, element); if (entry.isDirectory()) { if (!removeDirectory(entry)) { return false; } } else { if (!entry.delete()) { return false; } } } } } return directory.delete(); } }