加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

Path.resolve(其他)java.nio.file.Path方法

发布时间:2020-12-14 19:36:35 所属栏目:Java 来源:网络整理
导读:直接来自这个 API: resolve Path resolve(Path other) Resolve the given path against this path. If the other parameter is an absolute path then this method trivially returns other. If other is an empty path then this method trivially returns
直接来自这个 API:

resolve

Path resolve(Path other)

Resolve the given path against this path.

If the other parameter is an absolute path then this method trivially
returns other. If other is an empty path then this method trivially
returns this path. Otherwise this method considers this path to be a
directory and resolves the given path against this path. In the
simplest case,the given path does not have a root component,in which
case this method joins the given path to this path and returns a
resulting path that ends with the given path. Where the given path has
a root component then resolution is highly implementation dependent
and therefore unspecified.

(强调我的)

这里有一点矛盾,首先他们说:

>如果另一个参数是绝对路径,那么这个方法
平凡地返回其他.

然后他们说:
>如果给定路径具有根组件,则解决方案高度依赖于实现,因此未指定.

绝对路径是否必须包含根组件才能成为这样的组件?
提前致谢.

解决方法

对你的问题的简短回答是否定的,绝对路径不需要有根组件,但是,取决于提供者,它可能.

如果我们看一下source code for UnixPath,我们确实看到,如果它是一个绝对路径,那么它将返回一个根组件,它将只返回一个根组件.

但是,并不要求以这种方式实施.理论上至少,getRoot()可以返回一些东西,而isAbsolute()则返回false.在此,结果是不确定的.或者,将其放在真值图表格中:

Result of resolve() when:
                     getRoot()==null  getRoot()!=null
isAbsolute()==true   defined          defined
isAbsolute()==false  defined          undefined

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读