Java Path File Check nio isDirectoryEmpty(String dirPath)

Here you can find the source of isDirectoryEmpty(String dirPath)

Description

is Directory Empty

License

Open Source License

Declaration

private static boolean isDirectoryEmpty(String dirPath) throws IOException 

Method Source Code

//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*/
    }
}

Related

  1. isDirectory(Path fileOrDir, LinkOption... options)
  2. isDirectory(Path value)
  3. isDirectoryEmpty(Path dir)
  4. isDirectoryEmpty(Path directory)
  5. isDirectoryEmpty(Path path)
  6. isDirectoryInPath(File p, File d)
  7. isDirEmpty(final Path directory)
  8. isEmpty(Path dir)
  9. isEmptyDir(Path dir)