Here you can find the source of deleteFolder(String path)
public static void deleteFolder(String path)
//package com.java2s; //License from project: Open Source License import java.io.File; public class Main { public static void deleteFolder(String path) { File file = new File(path); if (file.exists()) { if (file.isFile()) { deleteFile(path);/*from www. j av a2 s .co m*/ } else { deleteDirectory(path); } } } private static void deleteFile(String filePath) { File file = new File(filePath); if (file.isFile() && file.exists()) file.delete(); } private static void deleteDirectory(String filePath) { if (!filePath.endsWith(File.separator)) { filePath = filePath + File.separator; } 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(); } }