List of utility methods to do Path File Check nio
boolean | isAbsolute(String path) is Absolute return toPath(path).isAbsolute();
|
boolean | isAbsolutePath(String path) is Absolute Path return Paths.get(path).isAbsolute();
|
boolean | isAsciiText(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; |
boolean | isBallerinaProject(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; |
boolean | isBinary(Path file) is Binary String fileName = file.getFileName().toString();
return (fileName.endsWith(JAR_SUFFIX)
&& !fileName.endsWith(SOURCE_JAR_SUFFIX));
|
boolean | isContained(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; ... |
boolean | isDirectory(Path fileOrDir, LinkOption... options) is Directory return Files.isDirectory(fileOrDir, options);
|
boolean | isDirectory(Path value) is Directory return Files.isDirectory(value);
|
boolean | isDirectoryEmpty(Path dir) is Directory Empty try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(dir)) { return !dirStream.iterator().hasNext(); |
boolean | isDirectoryEmpty(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; |