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

booleanisValidPath(String path)
Returns true if path can be converted into a Path via Paths#get(String) , otherwise returns false.
try {
    Paths.get(path);
} catch (InvalidPathException ipe) {
    return false;
return true;
booleanisValidPath(String path)
is Valid Path
try {
    Paths.get(path);
} catch (InvalidPathException ex) {
    return false;
return true;
booleanisValidRootArgument(Path argument)
is Valid Root Argument
return (Files.exists(argument) && Files.isDirectory(argument));
booleanisValidWildFlyHome(final Path path)
Validates the path is a valid WildFly directory by checking for a jboss-modules.jar .
return Files.exists(path.resolve("jboss-modules.jar"));
booleanisVideo(Path p)
is Video
return Files.probeContentType(p).matches("video/.*");
booleanisZip(Path path)

Helper method to check zip path.

return path.getClass().getSimpleName().endsWith("ZipPath");
booleanisZip(Path path)
is Zip
if (!Files.isRegularFile(path)) {
    return false;
try (ZipFile ignored = new ZipFile(path.toFile())) {
    return true;
} catch (IOException ignored) {
    return false;
booleanisZipFile(Path path)
Return true only if path is a zip file.
return Files.isRegularFile(path) && path.toString().toLowerCase().endsWith(".zip");
booleanisZipFile(Path path)
Check if the file matching the given path is a zip file or not.
File f = path.toFile();
if (f.isDirectory() || f.length() < 4) {
    return false;
try (DataInputStream inputStream = new DataInputStream(new FileInputStream(f))) {
    return inputStream.readInt() == 0x504b0304;
} catch (FileNotFoundException e) {
    return false;
...