Java Utililty Methods Path Exist nio

List of utility methods to do Path Exist nio

Description

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

Method

BooleancheckFileExists(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;
booleancheckFileExists(String path)
check File Exists
return Files.exists(new File(path).toPath());
booleancheckPathExistence(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);
booleandirectoryExist(String path)
directory Exist
return Files.isDirectory(Paths.get(path));
voidensureDirectoryExists(final Path fileLocation)
ensure Directory Exists
if (!Files.exists(fileLocation)) {
    try {
        Files.createDirectory(fileLocation);
    } catch (IOException e) {
        e.printStackTrace();
booleanexist(Path... paths)

Helper method to check Path existence.

for (Path path : paths) {
    assert Files.exists(path);
return true;
booleanexists(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();
booleanexists(Path path)
Tests whether a file exists.
return Files.exists(path);
booleanexists(Path path, LinkOption... options)
exists
return Files.exists(path, options);
booleanexists(Path value)
Check path exists
return (value == null || !Files.exists(value)) ? false : true;