Where is the resource file placed?
The resources directory in the image above is called the Resource directory (under Main, and Java if not created by yourself), after the project compiles the file will be placed in the Red Classes directory, note that if your resources directory does not have the Golden Resource directory icon, please again idea on the right This directory selects the Mark directory As-resources Root, so that after the project is compiled, your resources will be placed in the compilation directory.
How do I get these files?
After the resource file is compiled into the compiled directory, we can get the root directory of the compiled directory by Class.getResource ("/"). GetPath () method, so if we want to get the Times What should the file do? As follows:
Question1.class.getResource ("/question1/times"). GetPath ()
This method gets the path to the Times file and then reads the file using this path to
How do I write to the compiled directory?
We can get the root directory of the compiled directory, and then stitching the required paths to get the path to the target file, for example
String Path = Question1.class.getResource ("/"). GetPath () + "Question1/ret.txt"
In the end we can get a path like this:
/users/xxx/work/projects/train/target/classes/question1/ret.txt
Then use this path to write to the file
How MAVEN projects get paths in the idea compiler