Here you can find the source of clearDir(File dir)
public static boolean clearDir(File dir)
//package com.java2s; //License from project: Apache License import java.io.File; public class Main { public static boolean clearDir(File dir) { if (!dir.exists()) { return false; }//from w w w.j ava 2 s. c o m for (File file : dir.listFiles()) { if (file.isDirectory()) { clearDir(file); } if (!file.delete()) return false; } return true; } }