20230626 java.nio.file.Path

发布时间 2023-08-23 10:02:12作者: 流星<。)#)))≦

介绍

  • java.nio.file.Path
  • public interface Path extends Comparable, Iterable, Watchable
  • 表示的是一个目录名序列,其后还可以跟着一个文件名

API

static

  • of
    • Path of(String first, String... more)
    • 通过连接给定的字符串创建一个路径
    • 等同于 Paths.get

public

  • resolve

    • 如果 other 是绝对路径,那么就返回 other
    • 否则,返回通过连接 this 和 other 或得的路径
  • resolveSibling

    • 如果 other 是绝对路径,那么就返回 other
    • 否则,返回通过连接 this 的父路径和 other 获得的路径
  • relativize

    • resolve
    • 返回用 this 进行解析,相对于 other 的相对路径
  • normalize

    • 移除诸如 . 和 .. 等冗余的路径元素
  • isAbsolute

    • 是否绝对路径
  • toAbsolutePath

    • 返回与该路径等价的绝对路径
  • getFileSystem

    • 返回文件系统
  • getRoot

    • 返回该路径的根部件,或者在该路径没有任何根部件时,返回 null
  • getParent

    • 返回父路径,或者在该路径没有父路径时 ,返回 null
  • getFileName

    • 返回该路径的最后一个部件,或者在该路径没有任何部件时,返回 null
  • getName

    • Path getName(int index);
    • 目录名序列的第 index 项名称
  • getNameCount

    • int getNameCount();
    • 目录名序列的个数
  • subpath

    • Path subpath(int beginIndex, int endIndex);
    • 目录名序列的子路径
  • startsWith

  • endsWith

  • toUri

    • URI toUri();
    • 转 URI
  • toRealPath

    • Path toRealPath(LinkOption... options) throws IOException;
    • 返回真实路径,即在文件系统上的实际路径
  • toFile

    • 从该路径中创建一个 File 对象
    • 对应 File.toPath
  • register

    • java.nio.file.Watchable 定义的接口
    • 注册监视器