Java Path File Check nio isDirectoryEmpty(Path dir)

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

Description

is Directory Empty

License

Apache License

Parameter

Parameter Description
dir The directory to check to see if it contains files

Exception

Parameter Description
IOException an exception

Return

Whether or no the path contains files

Declaration

public static boolean isDirectoryEmpty(Path dir) throws IOException 

Method Source Code


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

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

public class Main {
    /**//  w w w  .  j a v a  2s  .  c  o m
     * @param dir The directory to check to see if it contains files
     * @return Whether or no the path contains files
     * @throws IOException
     */
    public static boolean isDirectoryEmpty(Path dir) throws IOException {
        try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(dir)) {
            return !dirStream.iterator().hasNext();
        }
    }
}

Related

  1. isBallerinaProject(Path path)
  2. isBinary(Path file)
  3. isContained(Path contained, Path container)
  4. isDirectory(Path fileOrDir, LinkOption... options)
  5. isDirectory(Path value)
  6. isDirectoryEmpty(Path directory)
  7. isDirectoryEmpty(Path path)
  8. isDirectoryEmpty(String dirPath)
  9. isDirectoryInPath(File p, File d)