Here you can find the source of deleteDir(File dir)
public static void deleteDir(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 deleteDir(File dir) throws IOException { if (dir.isFile()) throw new IOException("IOException -> BadInputException: not a directory."); File[] files = dir.listFiles(); if (files != null) { for (int i = 0; i < files.length; i++) { File file = files[i]; if (file.isFile()) { file.delete();//from ww w . j a va 2 s . c om } else { deleteDir(file); } } } // if dir.delete(); } }