I have a the following source structure
/src/main/java
/src/main/resources
/src/main/resources/stuff
/src/main/resources/stuff/1.txt
/src/main/resources/stuff/2.txt
In my code I access the files in the stuff folder via:
ClassLoader.class.getResource("/stuff/1.txt").getFile()
When this is deployed it is deployed like this:
/
/lib
/lib/my-app.jar
/lib/other.jar
/lib/stuff
Currently my classpath is set to: lib/*
but I can't resolve lib/stuff/1.txt
in the way I do above. What do I need to set on the classpath for the above code to work?
It might be the difference between using relative and absolute paths as pointed out in this blog .
ClassLoader.class.getResource("lib/stuff/1.txt").getFile()
As pointed out by @Gimby, it'd be more efficient to use getResourseAsStream()
.
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.