Here you can find the source of deleteDir(File dir)
public static void deleteDir(File dir)
//package com.java2s; //License from project: Apache License import java.io.File; public class Main { /**/*ww w .j a v a2 s .co m*/ * Deletes the specified dir recursively, throwing a * {@link RuntimeException} if the delete fails. */ public static void deleteDir(File dir) { deleteDirContent(dir); if (!dir.delete()) { throw new RuntimeException("Directory " + dir.getAbsolutePath() + " can't be deleted."); } } /** * Fully delete the content of he specified directory. */ public static void deleteDirContent(File dir) { final File[] files = dir.listFiles(); if (files != null) { for (final File file : files) { if (file.isDirectory()) { deleteDirContent(file); } file.delete(); } } } /** * Deletes the specified file, throwing a {@link RuntimeException} if the * delete fails. */ public static void delete(File file) { if (!file.delete()) { throw new RuntimeException("File " + file.getAbsolutePath() + " can't be deleted."); } } }