Java File Path Delete deleteDirectory(String path)

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

Description

delete Directory

License

Open Source License

Declaration

public static void deleteDirectory(String path) 

Method Source Code


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

import java.io.File;

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void deleteDirectory(String path) {
        File dirToDel = new File(path);
        if (dirToDel.exists()) {
            List<File> files = getFilesInDir(dirToDel);
            for (File f : files) {
                f.delete();//from  w  w  w .j  a v a2s  .c o m
            }
            dirToDel.delete();
        }
    }

    public static List<File> getFilesInDir(File dir) {
        List<File> output = new ArrayList<>();
        for (File file : dir.listFiles()) {
            if (file.isDirectory())
                output.addAll(getFilesInDir(file));
            else
                output.add(file);
        }
        return output;
    }
}

Related

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