Here you can find the source of deleteRecursive(File dir)
public static void deleteRecursive(File dir) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.IOException; public class Main { public static void deleteRecursive(File dir) throws IOException { if (!dir.exists()) return; deleteContentsRecursive(dir);//from w w w . ja v a 2 s . c om if (!dir.delete()) throw new IOException("Unable to delete " + dir); } /** * Deletes the contents of the given directory (but not the directory itself) * recursively. * * @throws IOException * if the operation fails. */ public static void deleteContentsRecursive(File file) throws IOException { File[] files = file.listFiles(); if (files == null) return; // non existent for (File child : files) { if (child.isDirectory()) deleteContentsRecursive(child); if (!child.delete()) throw new IOException("Unable to delete " + child.getPath()); } } }