Java Utililty Methods Path Resolve nio

List of utility methods to do Path Resolve nio

Description

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

Method

StringgetResolvableFilePath(String path)
Convert path string to validated file path string.
return getResolvableFilePath(Paths.get(path));
Pathresolve(final Optional parent, final String child)
Attempts to resolve the child against the parent.
return parent.map(p -> p.resolve(child)).orElse(Paths.get(child));
Pathresolve(Path base, String one, String... more)
resolve
if (more == null || more.length < 1) {
    return base.resolve(one);
StringBuilder builder = new StringBuilder(one);
for (String block : more) {
    builder.append('/').append(block);
return base.resolve(builder.toString());
...
Pathresolve(Path directory, String... parts)
Resolves the Path to the file or directory under the directory/parts[0]/parts[1]/.../parts[n].
Path current = directory;
for (String part : parts) {
    current = current.resolve(part);
return current;
Pathresolve(Path file, Path srcDir, Path destDir)
resolve
return destDir.resolve(srcDir.relativize(file));
Pathresolve(Path path1, Path path2)
Resolves paths, even if their file system are different.
if (path1.getFileSystem().equals(path2.getFileSystem())) {
    return path1.resolve(path2);
} else {
    if (path2.isAbsolute()) {
        return path2;
    } else {
        Path resolvedPath = path1;
        for (Path pathPart : path2) {
...
Listresolve(Path target, Collection paths)
resolve
List<Path> resolvedPaths = new ArrayList<>();
for (Path child : paths) {
    resolvedPaths.add(target.resolve(child));
return resolvedPaths;
Optionalresolve(Path workingDir, List paths, String file)
resolve
paths.add(workingDir);
Optional<Path> resolved = Optional.empty();
for (Path path : paths) {
    if (Files.exists(path) && !Files.isDirectory(path))
        path = path.getParent();
    Path possibility = path.resolve(file).normalize();
    if (Files.exists(possibility) && !Files.isDirectory(possibility)) {
        resolved = Optional.of(possibility);
...
PathresolveBagUri(final Path baseDir, final URI bagUri)
Resolves the supplied bag:// URI against a platform-specific base directory.
if (bagUri == null) {
    throw new IllegalArgumentException(
            String.format(ERR_RESOLVE_BAGURI + "bag uri was null.", "null", baseDir));
if (!bagUri.getScheme().equals(BAG_URI_SCHEME)) {
    throw new IllegalArgumentException(
            String.format(ERR_RESOLVE_BAGURI + "bag uri had incorrect scheme.", bagUri, baseDir));
if (baseDir == null) {
    throw new IllegalArgumentException(
            String.format(ERR_RESOLVE_BAGURI + "base directory was null", bagUri, "null"));
final Path originalDir = baseDir;
final Path normalizedDir = baseDir.normalize();
if (normalizedDir == null) {
    throw new RuntimeException(String.format(ERR_RESOLVE_BAGURI + "failed to normalize the base directory.",
            bagUri, originalDir));
final Path bagPath = Paths.get(bagUri.getAuthority(), bagUri.getPath());
return normalizedDir.resolve(bagPath);
PathresolveForSymbolic(final Path path)
resolve For Symbolic
if (Files.isSymbolicLink(path)) {
    final Path simLink = Files.readSymbolicLink(path);
    if (!simLink.isAbsolute()) {
        final Path symLinkParent = path.toAbsolutePath().getParent();
        return symLinkParent.resolve(simLink);
    return simLink;
return path;