Here you can find the source of resolve(Path path1, Path path2)
Parameter | Description |
---|---|
path1 | the given path |
path2 | the path to resolve against the given path |
public static Path resolve(Path path1, Path path2)
//package com.java2s; /*// www. j av a 2 s . c o m * COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Notice * * The contents of this file are subject to the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. A copy of the License is available at * http://www.opensource.org/licenses/cddl1.txt * * The Original Code is SoftSmithy Utility Library. The Initial Developer of the * Original Code is Florian Brunner (Sourceforge.net user: puce). All Rights Reserved. * * Contributor(s): . */ import java.nio.file.Path; public class Main { /** * Resolves paths, even if their file system are different. * * If the file system is the same, {@link Path#resolve(java.nio.file.Path)} is used. * * If {@code path2} is {@link Path#isAbsolute() absolute}, {@code path2} is returned. * * Else the resolved path gets calculated. * * @param path1 the given path * @param path2 the path to resolve against the given path * @return the resolved path */ public static Path resolve(Path path1, Path path2) { if (path1.getFileSystem().equals(path2.getFileSystem())) { return path1.resolve(path2); } else { if (path2.isAbsolute()) { return path2; } else { Path resolvedPath = path1; for (Path pathPart : path2) { resolvedPath = resolvedPath.resolve(pathPart.toString()); } return resolvedPath; } } } }