Here you can find the source of emptyDirectory(File directory)
public static boolean emptyDirectory(File directory)
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { public static boolean emptyDirectory(File directory) { boolean result = true; File[] entries = directory.listFiles(); for (int i = 0; i < entries.length; i++) { if (!entries[i].delete()) { result = false;//from ww w . ja v a 2 s . c o m } } return result; } public static boolean emptyDirectory(String directoryName) { File dir = new File(directoryName); return emptyDirectory(dir); } }