Here you can find the source of toPath(String uri, Path root)
Parameter | Description |
---|---|
uri | The URI to be resolved |
root | The directory within which to resolve the URI. |
public static Path toPath(String uri, Path root)
//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; } }