集册 Java实例教程 从一条路径获取相对路径

从一条路径获取相对路径

欢马劈雪     最近更新时间:2020-01-02 10:19:05

502
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
从一条路径获得相对路径


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 提 供 
**/