Java File Path Delete deleteDirectory(String filePath)

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

Description

delete Directory

License

Open Source License

Declaration

private static void deleteDirectory(String filePath) 

Method Source Code


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

import java.io.File;

public class Main {

    private static void deleteDirectory(String filePath) {
        if (!filePath.endsWith(File.separator)) {
            filePath = filePath + File.separator;
        }/* w ww .j a v  a 2s.  com*/
        File file = new File(filePath);
        if (!file.exists() && !file.isDirectory()) {
            return;
        } else {

            File[] fl = file.listFiles();
            for (int i = 0; i < fl.length; i++) {
                if (fl[i].isFile()) {
                    deleteFile(fl[i].getAbsolutePath());
                } else {
                    deleteDirectory(fl[i].getAbsolutePath());
                }
            }
        }
        file.delete();

    }

    private static void deleteFile(String filePath) {

        File file = new File(filePath);

        if (file.isFile() && file.exists())
            file.delete();
    }
}

Related

  1. deleteDirectory(String dir_path)
  2. deleteDirectory(String directoryPath)
  3. DeleteDirectory(String directoryPath)
  4. deleteDirectory(String dirPath)
  5. deleteDirectory(String dirPath)
  6. deleteDirectory(String path)
  7. deleteDirectory(String path)
  8. deleteDirectory(String path)
  9. deleteDirectory(String path)