Here you can find the source of delete(File dir)
public static void delete(File dir)
//package com.java2s; //License from project: Apache License import java.io.File; public class Main { public static void delete(File dir) { if (!dir.isDirectory()) { dir.delete();//w w w. j a va 2 s.c o m return; } String[] entries = dir.list(); for (String s : entries) { File currentFile = new File(dir.getPath(), s); if (currentFile.isDirectory()) { delete(currentFile); } currentFile.delete(); } dir.delete(); } }