【问题标题】:Creating a child NIO.2 Path from a parent Path instance从父 Path 实例创建子 NIO.2 Path
【发布时间】:2017-07-01 15:06:32
【问题描述】:

如果我已经有一个实例指向同一文件系统上的父目录,我该如何创建一个表示子路径的java.nio.file.Path 实例?

目前,我正在使用

final Path parent = Paths.get("usr", "local");
final Path child = Paths.get(parent.toString(), "bin");

--但这看起来不是很优雅。

我正在寻找某种java.io.File(File parent, String child) NIO.2 的构造函数。

【问题讨论】:

    标签: java path nio


    【解决方案1】:

    你可以写child = parent.resolve("bin");

    resolve 可以接受 Path 或 String 作为参数。

    【讨论】:

    • 这里还有一个很好的reference 示例。
    猜你喜欢
    • 2023-03-10
    • 2015-06-18
    • 2021-08-28
    • 2016-07-18
    • 1970-01-01
    • 1970-01-01
    • 2013-10-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多