Here you can find the source of deleteDirectory(String sPath)
public static boolean deleteDirectory(String sPath)
//package com.java2s; //License from project: Open Source License import java.io.File; public class Main { public static boolean deleteDirectory(String sPath) { boolean flag = false; if (!sPath.endsWith(File.separator)) { sPath = sPath + File.separator; }/*from www. j av a 2 s . co m*/ File dirFile = new File(sPath); if (!dirFile.exists() || !dirFile.isDirectory()) { return false; } flag = true; File[] files = dirFile.listFiles(); for (int i = 0; i < files.length; i++) { if (files[i].isFile()) { flag = files[i].delete(); if (!flag) break; } else { flag = deleteDirectory(files[i].getAbsolutePath()); if (!flag) break; } } if (!flag) return false; if (dirFile.delete()) { return true; } else { return false; } } }