Here you can find the source of cleanDir(String dir)
public static boolean cleanDir(String dir)
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); import java.io.File; public class Main { public static boolean cleanDir(String dir) { return deleteDir(new File(dir), false); }//from www. j a v a 2 s .co m public static boolean deleteDir(String dir) { return deleteDir(new File(dir), true); } public static boolean deleteDir(File dir, boolean deleteSelf) { if (dir.isDirectory()) { String[] children = dir.list(); for (String child : children) { boolean success = deleteDir(new File(dir, child), true); if (!success) { return false; } } } if (deleteSelf) { return dir.delete(); } else { return true; } } }