Here you can find the source of clearDirectory(File f)
public static void clearDirectory(File f) throws IOException
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { public static void clearDirectory(File f) throws IOException { if (!f.isDirectory()) { throw new IllegalArgumentException("Only directory can be cleared."); // NOI18N }/*from www. j a v a 2 s . com*/ for (File c : f.listFiles()) { delete(c); } } public static void delete(File f) throws IOException { if (f.isDirectory()) { for (File c : f.listFiles()) { delete(c); } } if (!f.delete()) { throw new IOException("Failed to delete file: " + f); // NOI18N } } }