Java Path Create nio toPath(String uri, Path root)

Here you can find the source of toPath(String uri, Path root)

Description

Computes a full path for a URI within a

License

Open Source License

Parameter

Parameter Description
uri The URI to be resolved
root The directory within which to resolve the URI.

Return

A for the given URI, under the given root.

Declaration

public static Path toPath(String uri, Path root) 

Method Source Code

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

import java.nio.file.Path;

public class Main {
    /**/*from  w w w  .j a v a 2 s. c  om*/
     * Computes a full path for a URI within a
     *
     * @param uri  The URI to be resolved
     * @param root The directory within which to resolve the URI.
     * @return A {@link Path} for the given URI, under the given root.
     */
    public static Path toPath(String uri, Path root) {
        String relative = stripLeadingSlash(uri);
        return root.resolve(relative);
    }

    /**
     * Ensures the given string does not have a leading slash. This is useful for ensuring relative paths don't have a leading slash.
     *
     * @param string The value to be altered if necessary.
     * @return If the given string has no leading slash, the string is returned, otherwise a string with any leading slashes removed.
     */
    public static String stripLeadingSlash(String string) {
        String result = string;
        while (string != null && result.length() > 0 && result.startsWith("/")) {
            result = result.substring(1);
        }
        return result;
    }
}

Related

  1. isTempCreatedFile(Path filePath)
  2. setTimes(FileTime lastModifiedTime, FileTime lastAccessTime, FileTime createTime, Path... files)
  3. toPath(@Nullable String plain)
  4. toPath(String first, String... more)
  5. toPath(String path)
  6. toPath(String value, Path defaultValue)
  7. toPathArray(File... files)
  8. toPaths(File... files)
  9. toPaths(Iterable files)