Here you can find the source of deleteRecursive(File dir)
public static boolean deleteRecursive(File dir)
//package com.java2s; import java.io.*; public class Main { /**/* w ww .j av a 2 s . c om*/ * Recursively deletes an entire directory hierarchy. * @return true iff the directory hierarchy was successfully deleted. */ public static boolean deleteRecursive(File dir) { if (!dir.exists()) return (true); boolean success = true; String files[] = dir.list(); if (files != null) { for (int i = 0; i < files.length; i++) { File file = new File(dir, files[i]); if (file.isDirectory()) success &= deleteRecursive(file); else success &= file.delete(); } } success &= dir.delete(); return (success); } }