Here you can find the source of isDirectoryEmpty(Path dir)
Parameter | Description |
---|---|
dir | The directory to check to see if it contains files |
Parameter | Description |
---|---|
IOException | an exception |
public static boolean isDirectoryEmpty(Path dir) throws IOException
//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(); } } }