Here you can find the source of isEmpty(Path dir)
public static boolean isEmpty(Path dir) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.nio.file.*; public class Main { public static boolean isEmpty(String dir) throws IOException { return isEmpty(Paths.get(dir)); }//from w ww . j a v a 2 s .co m public static boolean isEmpty(Path dir) throws IOException { try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) { return !stream.iterator().hasNext(); } } }