提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
在两个位置之间构建路径
import java.nio.file.Path; import java.nio.file.Paths; /** 来 自 n o w j a v a . c o m**/ public class Main { public static void main(String[] args) { Path path01 = Paths.get("test.txt"); Path path02 = Paths.get("test2.txt"); Path path03 = Paths.get("/folder2/folder3/test.txt"); Path path04 = Paths.get("/folder2/2011"); Path path01_to_path02 = path01.relativize(path02); System.out.println(path01_to_path02); Path path02_to_path01 = path02.relativize(path01); System.out.println(path02_to_path01); /** 来 自 时 代 J a v a - nowjava.com **/ Path path03_to_path04 = path03.relativiz