Here you can find the source of clearDirectory(String path)
public static void clearDirectory(String path)
//package com.java2s; //License from project: Apache License import java.io.File; public class Main { public static void clearDirectory(String path) { deleteDirectory(path);//from w ww .j a v a 2 s . c o m File dir = new File(path); if (!dir.exists()) dir.mkdir(); } public static boolean deleteDirectory(String path) { return deleteDirectory(new File(path)); } public static boolean deleteDirectory(File path) { if (path.exists()) { File[] files = path.listFiles(); for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) { deleteDirectory(files[i]); } else { files[i].delete(); } } } return (path.delete()); } }