Java Delete Folder deleteFolder(File file)

Here you can find the source of deleteFolder(File file)

Description

delete Folder

License

Open Source License

Declaration

public static void deleteFolder(File file) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2009, 2010 Progress Software Corporation.
 * 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
 ******************************************************************************/

import java.io.File;

public class Main {
    public static void deleteFolder(File file) {
        if (!file.isDirectory() || (file.isDirectory() && file.list().length == 0)) {
            file.delete();/*from w  w w .j  a  v a 2  s.  co m*/
        } else {
            File[] listFiles = file.listFiles();
            for (File childFile : listFiles) {
                deleteFolder(childFile);
            }
            file.delete();
        }
    }
}

Related

  1. deleteFolder(@Nonnull File file)
  2. deleteFolder(File dir, boolean deleteFolderItself)
  3. deleteFolder(File file)
  4. deleteFolder(File file)
  5. deleteFolder(File file, boolean deleteParent)
  6. deleteFolder(File file, boolean withCurrentFolder)