I’m trying to access a json file in a Spring boot project and the file is not under src main. Rather it is parallel to src. What is the path to this file if i want to create a Resource or File object to read from it.
I cannot move this file to app/src or app/test. It is directly under app. That is, it is in the same directory as pom.xml
From The Introduction to the Standard Directory Layout,
src/main/resources Application/Library resources
And then at the bottom, it continues –
Within artifact producing source directories (ie. main and test), there is one directory for the language java (under which the normal package hierarchy exists), and one for resources (the structure which is copied to the target classpath given the default resource definition).
2
Assuming your file in the project directory is file.txt
use this code to access it:
new File("file.txt")
Please note that if you build a JAR and run it outside of the project you won’t have this file. In that case Java will try to access it in the working directory.
1