繁体   English   中英

getClassLoader()。getResource()。getPath()未返回预期结果

[英]getClassLoader().getResource().getPath() not returning expected result

我正在测试(JUnit)在主目录下某个地方的类中的逻辑。
按照这种逻辑,我试图通过做类似的事情来获取“ dir3”的路径

this.getClass().getClassLoader().getResource("dir1/dir2/dir3").getPath()

但是,加载程序似乎找不到它。

当我将代码重写为

this.getClass().getClassLoader().getResource("dir1/dir2").getPath()

有用。

加载程序无法直接找到正确的路径(dir3)吗?


目录结构(Maven)

src
 |-main
 |   |-resources
 |        |-dir1
 |           |-dir2
 |              |-dir3
 |-test
     |-resources(empty)

@Thilo
谢谢。 的确直接被排除在外。 在其中放一些文件就可以完成这项工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM