Here you can find the source of isDirectoryEmpty(Path path)
public static boolean isDirectoryEmpty(Path path)
//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; } } }