Java Path File Check nio isValidPath(String path)

Here you can find the source of isValidPath(String path)

Description

Returns true if path can be converted into a Path via Paths#get(String) , otherwise returns false.

License

Open Source License

Parameter

Parameter Description
path A string representing the file path. Cannot be null.

Declaration

public static boolean isValidPath(String path) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.nio.file.InvalidPathException;

import java.nio.file.Paths;

public class Main {
    /**/*www  .  j  a va 2s  .co  m*/
     * Returns true if {@code path} can be converted into a {@code Path} via {@link Paths#get(String)},
     * otherwise returns false.
     * @param path A string representing the file path. Cannot be null.
     */
    public static boolean isValidPath(String path) {
        try {
            Paths.get(path);
        } catch (InvalidPathException ipe) {
            return false;
        }
        return true;
    }
}

Related

  1. isUnix(Path path)
  2. isValidDirectory(String path)
  3. isValidFileType(Path filePath)
  4. isValidHomeDirectory(final Path path)
  5. isValidPath(String path)
  6. isValidPath(String path)
  7. isValidRootArgument(Path argument)
  8. isValidWildFlyHome(final Path path)
  9. isVideo(Path p)