Java Path File Check nio isDirectoryEmpty(Path path)

Here you can find the source of isDirectoryEmpty(Path path)

Description

is Directory Empty

License

Open Source License

Declaration

public static boolean isDirectoryEmpty(Path path) 

Method Source Code


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

import java.io.IOException;

import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;

public class Main {
    public static boolean isDirectoryEmpty(Path path) {
        if (!Files.isDirectory(path)) {
            return false;
        }//from   w  w w . ja va 2  s .  c  o  m

        try (DirectoryStream<Path> ds = Files.newDirectoryStream(path)) {
            return !ds.iterator().hasNext();
        } catch (IOException ex) {
            return false;
        }
    }
}

Related

  1. isContained(Path contained, Path container)
  2. isDirectory(Path fileOrDir, LinkOption... options)
  3. isDirectory(Path value)
  4. isDirectoryEmpty(Path dir)
  5. isDirectoryEmpty(Path directory)
  6. isDirectoryEmpty(String dirPath)
  7. isDirectoryInPath(File p, File d)
  8. isDirEmpty(final Path directory)
  9. isEmpty(Path dir)