集册 Java实例教程 在两个位置之间创建路径

在两个位置之间创建路径

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

486
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
在两个位置之间创建路径

import java.nio.file.Path;

import java.nio.file.Paths;


public class Main {//from 时   代     Java  公  众  号 - nowjava.com

  public static void main(String[] args) {

    Path firstPath;

    Path secondPath;

    firstPath = Paths.get("music/Future Setting A.mp3");

    secondPath = Paths.get("docs");

    System.out.println("From firstPath to secondPath: "

        + firstPath.relativize(secondPath));

    System.out.println("From secondPath to firstPath: "

        + secondPath.relativize(firstPath));

    System.out.println();


    firstPath = Paths.get("music/Future Setting A.mp3");

    secondPath = Paths.get("music");

    System.out.println("From firstPath to secondPath: "

        + firstPath.relativize(secondPath));

    System.out.println("From secondPath to firstPath: "

        + secondPath.relativize(firstPath));

    System.out.println();//NowJava.com 提供


    firstPath = Paths.get("music/Future Setting A.mp3");

    secondPath = Paths.get("docs/users.txt");

    System.out.println(
展开阅读全文