Java Delete Tree deleteTree(File dir)

Here you can find the source of deleteTree(File dir)

Description

delete Tree

License

Open Source License

Declaration

public static void deleteTree(File dir) 

Method Source Code

//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();
            }
        }
    }
}

Related

  1. deleteTree(File dir)
  2. deleteTree(File f)
  3. deleteTree(File file, boolean check)
  4. deleteTree(final File file)
  5. delTree(File dir)