Here you can find the source of emptyFolder(File folder, boolean ignoreCannotDel)
static public int emptyFolder(File folder, boolean ignoreCannotDel) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.IOException; public class Main { static public int emptyFolder(File folder, boolean ignoreCannotDel) throws IOException { int counter = 0; if (folder.exists() && folder.isDirectory()) { File[] child = folder.listFiles(); for (int i = 0; i < child.length; i++) { File file = child[i]; if (file.isDirectory()) counter += emptyFolder(file, ignoreCannotDel); boolean result = file.delete(); if (!result && !ignoreCannotDel) { if (!ignoreCannotDel) { throw new IOException("Cannot delete " + file.getAbsolutePath()); } else { file.deleteOnExit(); }//from ww w.ja v a 2 s . c o m } else { counter++; } } } return counter; } }