Here you can find the source of deleteFolder(File folder)
public static boolean deleteFolder(File folder)
//package com.java2s; import java.io.File; public class Main { public static boolean deleteFolder(File folder) { boolean result = false; try {//from w w w. j a v a 2s. c o m String childs[] = folder.list(); if (childs == null || childs.length <= 0) { if (folder.delete()) { result = true; } } else { for (int i = 0; i < childs.length; i++) { String childName = childs[i]; String childPath = folder.getPath() + File.separator + childName; File filePath = new File(childPath); if (filePath.exists() && filePath.isFile()) { if (filePath.delete()) { result = true; } else { result = false; break; } } else if (filePath.exists() && filePath.isDirectory()) { if (deleteFolder(filePath)) { result = true; } else { result = false; break; } } } } folder.delete(); } catch (Exception e) { e.printStackTrace(); result = false; } return result; } }