Here you can find the source of deleteDirectory(String filePath)
private static void deleteDirectory(String filePath)
//package com.java2s; //License from project: Open Source License import java.io.File; public class Main { private static void deleteDirectory(String filePath) { if (!filePath.endsWith(File.separator)) { filePath = filePath + File.separator; }/* w ww .j a v a 2s. com*/ File file = new File(filePath); if (!file.exists() && !file.isDirectory()) { return; } else { File[] fl = file.listFiles(); for (int i = 0; i < fl.length; i++) { if (fl[i].isFile()) { deleteFile(fl[i].getAbsolutePath()); } else { deleteDirectory(fl[i].getAbsolutePath()); } } } file.delete(); } private static void deleteFile(String filePath) { File file = new File(filePath); if (file.isFile() && file.exists()) file.delete(); } }