Here you can find the source of deleteTree(File dir)
public static void deleteTree(File dir)
//package com.java2s; /*// w w w. j a va 2 s. c o m * Copyright (c) 2006-2012 Nuxeo SA (http://nuxeo.com/) and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Nuxeo - initial API and implementation * */ import java.io.File; public class Main { public static void deleteTree(File dir) { emptyDirectory(dir); dir.delete(); } public static void emptyDirectory(File dir) { File[] files = dir.listFiles(); if (files == null) { return; } int len = files.length; for (int i = 0; i < len; i++) { File file = files[i]; if (file.isDirectory()) { deleteTree(file); } else { file.delete(); } } } }