Here you can find the source of deleteFileSystemDirectory(String dirPath)
public static void deleteFileSystemDirectory(String dirPath)
//package com.java2s; import java.io.*; public class Main { public static void deleteFileSystemDirectory(String dirPath) { deleteFileSystemDirectory(new File(dirPath)); }//from www . j a v a 2 s .co m public static void deleteFileSystemDirectory(File current) { File[] files = current.listFiles(); for (int i = 0; files != null && i < files.length; i++) { File file = files[i]; if (file.isDirectory()) deleteFileSystemDirectory(file); else deleteFile(file); } deleteFile(current); } public static void deleteFile(String filename) { deleteFile(new File(filename)); } public static void deleteFile(File file) { if (!file.exists()) return; if (!file.delete()) throw new RuntimeException("Could not delete '" + file.getAbsoluteFile() + "'"); waitUntilFileDeleted(file); } private static void waitUntilFileDeleted(File file) { int i = 10; while (file.exists()) { if (--i <= 0) { System.out.println("Breaking out of delete wait"); break; } try { Thread.sleep(500); } catch (InterruptedException e) { } } } }