集册 Java实例教程 通过规范化路径消除冗余

通过规范化路径消除冗余

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

507
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
通过标准化路径来消除冗余
//时 代      J a v a   公   众 号 - nowjava.com 提供

import java.nio.file.Path;

import java.nio.file.Paths;


public class Main {

  public static void main(String[] args) {

    Path path = Paths.get("/home/docs/../music/SpaceMachine A.mp3");

    System.out.println("Absolute path: " + path.toAbsolutePath());

    System.out.println("URI: " + path.toUri());

    System.out.println("Normalized Path: " + path.normalize());

    System.out.println("Normalized URI: " + path.normalize().toUri());

    System.out.println();

    path = Paths.get("/home/./music/ Robot Brain A.mp3");

    System.out.println("Absolute path: " + path.toAbsolutePath());

    System.out.println("URI: " + path.toUri())
展开阅读全文