Here you can find the source of deleteDirectory(String dirPath)
public static void deleteDirectory(String dirPath) throws Exception
//package com.java2s; // it under the terms of the GNU General Public License as published by import java.io.*; public class Main { public static void deleteDirectory(String dirPath) throws Exception { deleteDirectory(new File(dirPath)); }// ww w. j a va2 s.co m public static void deleteDirectory(File dir) throws Exception { cleanDirectory(dir); dir.delete(); } public static void cleanDirectory(String dirPath) throws Exception { cleanDirectory(new File(dirPath)); } public static void cleanDirectory(File dir) throws Exception { if (!dir.exists()) return; if (!dir.isDirectory()) throw new Exception("The path '" + dir.getPath() + "' is not a directory. "); File[] fs = dir.listFiles(); for (File f : fs) { if (f.isDirectory()) deleteDirectory(f.getPath()); else f.delete(); } } /** * list all files of a given folder * * @param dirPath a given folder * @return file list */ public static File[] listFiles(String dirPath) { File dir = new File(dirPath); if (dir.isDirectory()) return dir.listFiles(); else return new File[] { dir }; } }