Here you can find the source of deltree(String dir)
public static boolean deltree(String dir)
//package com.java2s; /*//from w w w . j ava 2 s . co m * Copyright (C) ${year} Omry Yadan <${email}> * All rights reserved. * * See https://github.com/omry/banana/blob/master/BSD-LICENSE for licensing information */ import java.io.*; public class Main { public static boolean deltree(String dir) { File f = new File(dir); if (f.isDirectory()) { File[] files = f.listFiles(); for (File ff : files) deltree(ff.getAbsolutePath()); } return f.delete(); } public static boolean deltree(File root, String dir) { boolean b = deltree(new File(root, dir).getAbsolutePath()); while (true) { if (dir != null && !dir.equals("") && !dir.equals(File.separator) && dir.length() > 0) { File f = new File(root, dir); if (f.isDirectory() && f.exists()) { File[] files = f.listFiles(); if (files.length == 0) // empty dir. f.delete(); else break; } dir = new File(dir).getParent(); } else { break; } } return b; } }