Here you can find the source of deleteDirectory(File dir)
public static void deleteDirectory(File dir)
//package com.java2s; //License from project: Open Source License import java.io.File; public class Main { public static void deleteDirectory(File dir) { if (!dir.exists()) return; File[] subs = dir.listFiles(); if (subs != null) { for (File f : dir.listFiles()) { if (f.isFile()) { if (!f.delete()) { throw new IllegalStateException( "delete file failed: " + f); }//w w w . ja v a2 s . c o m } else { deleteDirectory(f); } } } if (!dir.delete()) { throw new IllegalStateException("delete directory failed: " + dir); } } }