简体   繁体   English

无法获取资源

[英]Unable to getResources

My Spring project test folder structure is as follow: 我的Spring项目测试文件夹结构如下:

test/resources/spring/jobs

test/resources/testfiles/

My goal is to write file to testfiles folder 我的目标是将文件写入testfiles文件夹

When I do the following, it returns me to the build path URL: 当我执行以下操作时,它将返回到构建路径URL:

getClass().getClassLoader().getResource("spring/jobs")

/Users/xxx/Projects/test-project/build/resources/test/spring/jobs

However, when I do the following, it simply returns a null: 但是,当我执行以下操作时,它只是返回一个null:

getClass().getClassLoader().getResource("testfiles")

I am writing test and my goal is to write files to the testfiles folder in the resources folder? 我正在编写测试,我的目标是将文件写入资源文件夹中的testfiles文件夹吗?

/Users/xxx/Projects/test-project/src/test/resources/testfiles/ 

What am I doing wrong? 我究竟做错了什么?

The resource path is not considered writable, so you simply shouldn't do this. 资源路径不被认为是可写的,因此您根本不应该这样做。 Create a temporary directory instead. 而是创建一个临时目录。

(And the reason for the null return is that the directory itself isn't considered a resource and isn't usually available.) (返回空值的原因是目录本身不被视为资源,并且通常不可用。)

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

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