How classes in a jar package read configuration files inside and outside the package

Source: Internet
Author: User


Recently packaged the code into a jar package, for information on how to handle reading the configuration file is hereby recorded.

The directory structure is as follows
    1. Out.properties
    2. A.jar
    3. -com
    4. -A.class
    5. -in.properties



As shown above, Out.properties is in the A.jar package in the same file directory;
The in.properties is inside the A.jar package.

About A.class How to read a configuration file inside a jar or outside the jar,
As shown below:

Java code
    1. FileInputStream inputStream1 = new FileInputStream ("out.properties");
    2. InputStream inputStream2 = A.class.getresourceasstream ("/in.properties");



In addition, the log4j configuration file log4j.properties can be placed in the same directory as the jar package and will automatically take effect.

If the XML file and the jar package are in the same directory, then there is no difference in classpath. Can read directly, load

How classes in a jar package read configuration files inside and outside the package

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.