Here you can find the source of clearDirctory(File dir)
public static void clearDirctory(File dir)
//package com.java2s; //License from project: Open Source License import java.io.File; public class Main { public static void clearDirctory(File dir) { deleteR(dir, false);/*from w w w. jav a 2 s . co m*/ } public static void deleteR(File dir) { deleteR(dir, true); } private static void deleteR(File file, boolean deleteRoot) { File[] listFiles = file.listFiles(); if (listFiles != null) { for (File child : listFiles) { deleteR(child, true); } } if (deleteRoot) { file.delete(); } } }