Java Folder Delete nio deleteEmptyFolder(String... dirNames)

Here you can find the source of deleteEmptyFolder(String... dirNames)

Description

delete Empty Folder

License

Apache License

Declaration

static void deleteEmptyFolder(String... dirNames) throws Exception 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.File;

import java.io.IOException;

import java.nio.file.Files;

public class Main {
    static final String JUNIT_SUFFIX = " (JUNIT)";
    private static String drive;

    static void deleteEmptyFolder(String... dirNames) throws Exception {
        File dir = generateFileObject(dirNames);
        System.out.println("Deleting folder '" + dir + "'");
        try {//from  w ww.  j ava2  s  . c  o m
            Files.delete(dir.toPath());
        } catch (IOException e) {
            throw new Exception(e.getClass().getSimpleName()
                    + " deleting empty folder '" + dir + "' : "
                    + e.getMessage());
        }
    }

    static File generateFileObject(String... dirNames) {
        String dirPath = drive + ":";
        for (String dirName : dirNames) {
            dirPath += "\\" + dirName + JUNIT_SUFFIX;
        }
        return new File(dirPath);
    }
}

Related

  1. delete(Path folder, List noDeleteFiles)
  2. deleteFile(String folderName, String fileName)
  3. deleteFolder(Path folder)
  4. deleteFolder(Path path)
  5. deleteFolderAndSubfolders(Path pathToFile)