How MAVEN projects get paths in the idea compiler

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.