Here you can find the source of deltree(File directory)
public static boolean deltree(File directory)
//package com.java2s; /*/* www . j a v a 2s . com*/ * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2006. * * Licensed under the Aduna BSD-style license. */ import java.io.File; public class Main { /** * Deletes the given file and everything under it. * * @return Whether all files were deleted succesfully. */ public static boolean deltree(File directory) { if (directory == null || !directory.exists()) { return true; } boolean result = true; if (directory.isFile()) { result = directory.delete(); } else { File[] list = directory.listFiles(); for (int i = list.length; i-- > 0;) { if (!deltree(list[i])) { result = false; } } if (!directory.delete()) { result = false; } } return result; } }