集册 Java实例教程 组合两条路径

组合两条路径

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

569
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
合并两个路径可以使您定义固定的根路径,并在其中附加部分路径。

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) {             


        //define the fix path

        Path base_1 = Paths.get("C:/folder1/folder2/folder4");

        Path base_2 = Paths.get("C:/folder1/folder2/folder3/test.txt");


        //resolve test.txt file

        Path path_1 = base_1.resolve("test.txt");

        System.out.println(path_1.toString());
/**来 自 时代Java公众号**/

        //resolve test2.txt file

        Path path_2 = base_1.resolve("test2.txt");

        System.out.println(path_2.toString());

        

        
展开阅读全文