Here you can find the source of cleanDirectory(String dirPath)
public static void cleanDirectory(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 cleanDirectory(String dirPath) throws Exception { cleanDirectory(new File(dirPath)); }// www .j a v a 2 s.co m 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 }; } public static void deleteDirectory(String dirPath) throws Exception { deleteDirectory(new File(dirPath)); } public static void deleteDirectory(File dir) throws Exception { cleanDirectory(dir); dir.delete(); } }