【问题标题】:Relative file system URL specification相对文件系统 URL 规范
【发布时间】:2017-11-18 15:24:24
【问题描述】:

在一些单元测试中,我们最初将此类资源链接用于java.net.URL

"https://<host name>/<project name>/pom.xml"

用于加载测试数据。但是在离线开发的时候就不行了。

如何从文件系统中的test/java 文件夹 URL 中指定相对 URL?

我试过"file:///../pom.xml",但它带来了异常

java.io.FileNotFoundException: \..\pom.xml (The system cannot find the file specified)

如果我指定"file://..\\pom.xml" 我会收到

Caused by: java.net.UnknownHostException: ..

【问题讨论】:

标签: java url


【解决方案1】:

答案是使用file: 协议规范,不带斜线。由于 JUnit 将项目文件夹视为根目录,因此在我的情况下,指向 pom.xml 的正确链接很简单 file:pom.xml

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-07
    • 2015-03-25
    相关资源
    最近更新 更多