WebSphere Gets the project under the. Properties path

Source: Internet
Author: User

A: If the container is WebSphere, then the red place below cannot be added "/", and if it is Tomcat, add "/",

Java code
    1. String Path = this .   Class.getResource (""). GetPath () +"config.properties";
    2. Properties properties= new properties ();
    3. Properties.load (new FileInputStream (path));

If your config.properties is under a package, bring the package together, such as: Config.properties under the Com.df.util package:

Java code
    1. String Path = this .   Class.getResource (""). GetPath () +"com/df/util/config.properties";
    2. Properties properties= new properties ();
    3. Properties.load (new FileInputStream (path));

Second: If you use spring in your project, you can also get it,

Java code
    1. Import Org.springframework.core.io.Resource;
    2. Import Org.springframework.core.io.ClassPathResource;
    3. Resource Resource = new Classpathresource ("config.properties"); Read directly under SRC, under the class file
    4. Properties properties= new properties ();
    5. InputStream in = Resource.getinputstream ();
    6. Properties.load (in);

WebSphere Gets the project under the. Properties path

Related Article

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.