Here you can find the source of cleanDirectory(File dir)
public static File cleanDirectory(File dir)
//package com.java2s; //License from project: Open Source License import java.io.File; public class Main { public static File cleanDirectory(File dir) { if (dir.isFile()) { return null; }/* w w w . j a v a 2 s .c o m*/ delete(dir); dir.mkdirs(); return dir; } public static boolean isFile(File file) { return file != null && file.isFile(); } public static void delete(File root) { if (root.isFile()) { root.delete(); return; } File[] files = root.listFiles(); if (files != null) { for (File file : files) { delete(file); } } root.delete(); } }