Here you can find the source of clearDirectory(String dir)
public static void clearDirectory(String dir) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.IOException; public class Main { public static void clearDirectory(String dir) throws IOException { File f = new File(dir); if (!f.exists()) { throw new IOException("Directory not present or not writable"); }// w ww . j a va2 s . c o m if (f.isDirectory()) { deleteFolder(f); } else { throw new IOException("Is not a directory"); } } public static void deleteFolder(File folder) { File[] files = folder.listFiles(); if (files != null) { for (File f : files) { if (f.isDirectory()) { deleteFolder(f); } else { f.delete(); } } } folder.delete(); } }