Here you can find the source of deleteDirectory(String folder)
public static boolean deleteDirectory(String folder)
//package com.java2s; // %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt import java.io.File; public class Main { public static boolean deleteDirectory(String folder) { String dir = folder;// w ww. ja v a2s . co m if (!dir.endsWith(File.separator)) { dir = dir + File.separator; } File dirFile = new File(dir); if (!dirFile.exists() || !dirFile.isDirectory()) { return false; } boolean flag = true; // delete all the file File[] files = dirFile.listFiles(); for (File file : files) { // delete the file if (file.isFile()) { flag = deleteFile(file.getAbsolutePath()); if (!flag) { break; } } else { flag = deleteDirectory(file.getAbsolutePath()); if (!flag) { break; } } } if (!flag) { return false; } // delete the directory if (dirFile.delete()) { return true; } else { return false; } } public static boolean deleteFile(String fileName) { File file = new File(fileName); if (file.isFile() && file.exists()) { file.delete(); return true; } else { return false; } } }