Java File Path Delete deleteFolder(String filePath)

Here you can find the source of deleteFolder(String filePath)

Description

delete Folder

License

Open Source License

Declaration

public static void deleteFolder(String filePath) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;

public class Main {
    public static void deleteFolder(String filePath) {
        File file = new File(filePath);
        if (file.exists()) {
            if (file.isFile()) {
                file.delete();/*  w  w  w  .jav  a  2  s  . co m*/
            } else if (file.isDirectory()) {
                File[] files = file.listFiles();

                for (int i = 0; i < files.length; ++i) {
                    deleteFolder(files[i]);
                }
            }

            file.delete();
        }

    }

    public static void deleteFolder(File file) {
        if (file.exists()) {
            if (file.isFile()) {
                file.delete();
            } else if (file.isDirectory()) {
                File[] files = file.listFiles();

                for (int i = 0; i < files.length; ++i) {
                    deleteFolder(files[i]);
                }
            }

            file.delete();
        }

    }
}

Related

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