Here you can find the source of clearDir(File dir, boolean clearsubdirs)
static public void clearDir(File dir, boolean clearsubdirs)
//package com.java2s; /* Copyright 2012, UCAR/Unidata. See the LICENSE file for more information. *//*from ww w. java 2 s. c o m*/ import java.io.*; public class Main { static public void clearDir(File dir, boolean clearsubdirs) { // wipe out the dir contents if (!dir.exists()) return; for (File f : dir.listFiles()) { if (f.isDirectory()) { if (clearsubdirs) { clearDir(f, true); // clear subdirs f.delete(); } } else f.delete(); } } }