Java File Path Delete deleteFolder(File path)

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

Description

delete Folder

License

Open Source License

Declaration

public static void deleteFolder(File path) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2000, 2010 IBM Corporation 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:/*from w  w  w .  ja  va  2 s. c  o  m*/
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

import java.io.File;

public class Main {
    private final static int MAX_RETRY = 5;

    public static void deleteFolder(File path) {
        if (path.isDirectory()) {
            for (File file : path.listFiles()) {
                file.delete();
            }
            path.delete();
        }
    }

    public static void delete(File file) {
        if (file.exists()) {
            for (int i = 0; i < MAX_RETRY; i++) {
                if (file.delete()) {
                    i = MAX_RETRY;
                } else {
                    try {
                        Thread.sleep(1000); // sleep a second
                    } catch (InterruptedException e) {
                        // don't need to catch this
                    }
                }
            }
        }
    }
}

Related

  1. deleteFilesRecursive(final File path)
  2. deleteFileSystemDirectory(String dirPath)
  3. deleteFileSystemDirectory(String dirPath)
  4. deleteFileWithoutException(final String path)
  5. deleteFileWithSuffix(String path, String suffix)
  6. deleteFolder(File path)
  7. deleteFolder(String filePath)
  8. deleteFolder(String folderPath)
  9. deleteFolder(String folderPath)