Java Directory Delete emptyDirectory(File dir)

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

Description

empty Directory

License

Open Source License

Declaration

public static void emptyDirectory(File dir) 

Method Source Code

//package com.java2s;
/*// w w w.  j  av a2 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 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();
            }
        }
    }

    public static void deleteTree(File dir) {
        emptyDirectory(dir);
        dir.delete();
    }
}

Related

  1. emptyDir(File dir)
  2. emptyDir(File directory)
  3. emptyDir(String dirName)
  4. emptyDir(String path)
  5. emptyDirectory(File dir)
  6. emptyDirectory(File dir)
  7. emptyDirectory(File dir)
  8. emptyDirectory(File directory)
  9. emptyDirectory(File directory)