提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
从一条路径获得相对路径
import java.nio.file.Path; import java.nio.file.Paths; /** n o w j a v a . c o m **/ public class NormalizeWeirdBehaviour { public static void main(String[] args) { Path p1 = Paths.get("/personal/./photos/../readme.txt"); Path p2 = Paths.get("/personal/index.html"); Path p3 = p1.relativize(p2); System.out.println(p3); // try to guess it before you run it... } } /** * n o w j a v a . c o m 提 供 **/