提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
针对当前路径的父路径解析传递的路径
import java.nio.file.Path; import java.nio.file.Paths; public class Main { /** 来 自 时 代 J a v a 公 众 号 - nowjava.com **/ public static void main(String[] args) { // define the fixed path Path base = Paths.get("C:/folder1/folder2/folder3/test.txt"); // resolve sibling test2.txt file Path path = base.resolveSibling("test2.txt"); System.out.println(path.toString()); } }