Java Utililty Methods Path File Check nio

List of utility methods to do Path File Check nio

Description

The list of methods to do Path File Check nio are organized into topic(s).

Method

booleanisAbsolute(String path)
is Absolute
return toPath(path).isAbsolute();
booleanisAbsolutePath(String path)
is Absolute Path
return Paths.get(path).isAbsolute();
booleanisAsciiText(Path p)
Guess whether a file is ASCII text format, using a default threshold where the number of non-ASCII characters found must be < 30%
char[] buf = new char[DEFAULT_BLOCK_SIZE];
try (BufferedReader reader = Files.newBufferedReader(p, Charset.forName("US-ASCII"))) {
    reader.read(buf);
} catch (MalformedInputException e) {
    return false;
return true;
booleanisBallerinaProject(Path path)
Is path is a valid ballerina project directory.
boolean isProject = false;
Path cachePath = path.resolve(".ballerina");
if (Files.exists(cachePath)) {
    isProject = true;
return isProject;
booleanisBinary(Path file)
is Binary
String fileName = file.getFileName().toString();
return (fileName.endsWith(JAR_SUFFIX)
        && !fileName.endsWith(SOURCE_JAR_SUFFIX));
booleanisContained(Path contained, Path container)
Inspired by http://stackoverflow.com/questions/18227634/check-if-file-is-in-subdirectory
Path current = contained.normalize();
while (current != null) {
    if (Files.isSameFile(container, current)) {
        return true;
    current = current.getParent();
return false;
...
booleanisDirectory(Path fileOrDir, LinkOption... options)
is Directory
return Files.isDirectory(fileOrDir, options);
booleanisDirectory(Path value)
is Directory
return Files.isDirectory(value);
booleanisDirectoryEmpty(Path dir)
is Directory Empty
try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(dir)) {
    return !dirStream.iterator().hasNext();
booleanisDirectoryEmpty(Path directory)
Check if the directory is empty.
boolean retval = true;
DirectoryStream<Path> dirStream = Files.newDirectoryStream(directory);
if (dirStream.iterator().hasNext()) {
    retval = false;
dirStream.close();
return retval;