相对文件系统URL规范

时间:2017-06-16 01:06:49

标签: java url

在一些单元测试中,我们最初使用了java.net.URL

的资源链接

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

用于加载测试数据。但是,它在离线开发期间不起作用。

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

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

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

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

Caused by: java.net.UnknownHostException: ..

1 个答案:

答案 0 :(得分:0)

答案是使用file:协议规范而不遵循斜杠。由于JUnit认为作为根,我的案例中的项目文件夹正确链接到pom.xml很简单file:pom.xml

相关问题