Here you can find the source of deleteDir(File dir)
public static boolean deleteDir(File dir)
//package com.java2s; import java.io.File; import java.io.IOException; public class Main { public static boolean deleteDir(File dir) { if (dir == null) return false; File candir;/*from w w w . j av a 2s . c o m*/ try { candir = dir.getCanonicalFile(); } catch (IOException e) { return false; } if (!candir.equals(dir.getAbsoluteFile())) return false; File files[] = candir.listFiles(); if (files != null) { for (int i = 0; i < files.length; i++) { File file = files[i]; boolean deleted = !file.delete(); if (deleted && file.isDirectory()) deleteDir(file); } } return dir.delete(); } }