Here you can find the source of isDirectoryEmpty(String dirPath)
private static boolean isDirectoryEmpty(String dirPath) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2016 EfficiOS Inc., Alexandre Montplaisir * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which * accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html *******************************************************************************/ import java.io.IOException; import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; public class Main { private static boolean isDirectoryEmpty(String dirPath) throws IOException { Path path = Paths.get(dirPath); try (DirectoryStream<Path> stream = Files.newDirectoryStream(path)) { return !stream.iterator().hasNext(); }/* www . j a v a 2 s.c o m*/ } }