List of utility methods to do Path Exist nio
Boolean | checkFileExists(Path path, LinkOption... options) Checks if a file exists - Note: according to the Java tutorial - Checking a File or Directory: The methods in the Path class are syntactic, meaning that they operate on the Path instance.if (Files.exists(path, options)) { return Boolean.TRUE; } else if (Files.notExists(path, options)) { return Boolean.FALSE; } else { return null; |
boolean | checkFileExists(String path) check File Exists return Files.exists(new File(path).toPath()); |
boolean | checkPathExistence(String path) check Path Existence java.nio.file.Path p; try { p = java.nio.file.Paths.get(path); } catch (java.nio.file.InvalidPathException ipe) { return false; return java.nio.file.Files.exists(p); |
boolean | directoryExist(String path) directory Exist return Files.isDirectory(Paths.get(path));
|
void | ensureDirectoryExists(final Path fileLocation) ensure Directory Exists if (!Files.exists(fileLocation)) { try { Files.createDirectory(fileLocation); } catch (IOException e) { e.printStackTrace(); |
boolean | exist(Path... paths) Helper method to check Path existence. for (Path path : paths) { assert Files.exists(path); return true; |
boolean | exists(Path file) We are using java.io because sonar has suggested as a performance update https://sonarqube.com/coding_rules#rule_key=squid%3AS3725 return file != null && file.toFile().exists();
|
boolean | exists(Path path) Tests whether a file exists. return Files.exists(path);
|
boolean | exists(Path path, LinkOption... options) exists return Files.exists(path, options);
|
boolean | exists(Path value) Check path exists return (value == null || !Files.exists(value)) ? false : true;
|