Here you can find the source of emptyDir(File dir)
protected static void emptyDir(File dir) throws IOException
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.IOException; public class Main { public static void emptyDir(String path) throws IOException { File dir = new File(path); emptyDir(dir);//from ww w . ja v a2s. com } protected static void emptyDir(File dir) throws IOException { if (!(dir.exists() && dir.canWrite())) { throw new IOException( "Kann Verzeichnis nicht leeren, es ist nicht vorhanden " + "oder nicht beschreibbar"); } if (dir.isDirectory()) { String[] children = dir.list(); for (int i = 0; i < children.length; i++) { File current = new File(dir, children[i]); if (current.isDirectory()) { deleteDirectoryRecursivly(current); } if (current.isFile()) { current.delete(); } } } else { throw new IOException("Kann Datei nicht leeren"); } } public static void deleteDirectoryRecursivly(String path) throws IOException { File file = new File(path); deleteDirectoryRecursivly(file); } public static void deleteDirectoryRecursivly(File dir) throws IOException { if (dir.isDirectory()) { String[] children = dir.list(); for (int i = 0; i < children.length; i++) { deleteDirectoryRecursivly(new File(dir, children[i])); } } dir.delete(); } }