Here you can find the source of clearDirectory(File dir)
public static void clearDirectory(File dir)
//package com.java2s; //License from project: Open Source License import java.io.File; public class Main { public static void clearDirectory(File dir) { for (File f : dir.listFiles()) { delete(f);// w w w .j a v a2 s . c o m } } public static void delete(File file) { if (file != null && file.exists()) { if (file.isDirectory()) { File[] files = file.listFiles(); for (File f : files) { delete(f); } } file.delete(); } } }