解析(路径其他)用于根据该路径解析给定路径的java.nio.file.Path方法。此方法将两条路径连接在一起。如果此路径为“C/temp”,传递的路径为“drive/newFile”,则此方法将在该路径的末尾添加传递的路径,并使用“/”作为分隔符。因此,已解析的路径将为“C/temp/drive/newFile”。
如果other参数是绝对路径,则此方法会简单地返回other。如果other是空路径,则此方法将简单返回此路径。否则,此方法认为该路径是目录,并根据该路径解析给定路径。在最简单的情况下,给定路径没有根组件,在这种情况下,此方法将给定路径连接到该路径,并返回以给定路径结尾的结果路径。如果给定路径具有根成分,则解决方案高度依赖于实现,因此未指定。
用法:
Path resolve(Path other)
参数:此方法接受一个单独的参数other,这是要针对该路径解析的路径。
返回值:此方法返回结果路径。
以下示例程序旨在说明resolve(Path other)方法:
示例1:
// Java program to demonstrate
// Path.resolve(Path other) method
import java.nio.file.*;
public class GFG {
public static void main(String[] args)
{
// create an object of Path
Path path
= Paths.get("drive\\temp\\Spring");
// create an object of Path
// to pass to resolve method
Path path2
= Paths.get("programes\\workspace");
// call resolve()
// to create resolved Path
Path resolvedPath
= path.resolve(path2);
// print result
System.out.println("Resolved Path:"
+ resolvedPath);
}
}
输出: