Here you can find the source of cleanDirectory(File dir)
public static void cleanDirectory(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 cleanDirectory(File dir) throws IOException { File[] files = dir.listFiles(); if (files != null) { for (File f : files) { if (f.isFile()) { boolean deleted = f.delete(); if (!deleted) { throw new IOException("file:" + f.getAbsolutePath() + " not deleted"); }//from w ww . jav a 2s . c om } else { deleteDirectory(f); } } } } public static void deleteDirectory(File dir) throws IOException { File[] files = dir.listFiles(); if (files != null) { for (File f : files) { if (f.isDirectory()) { deleteDirectory(f); } else { boolean deleted = f.delete(); if (!deleted) { throw new IOException("file:" + f.getAbsolutePath() + " not deleted"); } } } } boolean deleted = dir.delete(); if (!deleted) { throw new IOException("dir:" + dir.getAbsolutePath() + " not deleted"); } } }