简体   繁体   中英

Unable to getResources

My Spring project test folder structure is as follow:

test/resources/spring/jobs

test/resources/testfiles/

My goal is to write file to testfiles folder

When I do the following, it returns me to the build path 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:

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

I am writing test and my goal is to write files to the testfiles folder in the resources folder?

/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.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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