Read the configuration file in java and read the configuration file in java.

Source: Internet
Author: User

Read the configuration file in java and read the configuration file in java.

If a java web project is running on tomcat or other containers, you can use the following method to obtain the file input stream:

1. When the property file is placed under src

InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("test.properties");Properties p = new Properties();p.load(is);

2. When the property file is placed under a package, such as com. test. config

InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("com/test/config/test.properties");Properties p = new Properties();p.load(is);

If it is a java project, use the following method to read the attribute file:

InputStream is = ClassLoader.getSystemResourceAsStream("test.properties");Properties p = new Properties();p.load(is);
If the property file is placed under a package, use com/test/config/test. properties.

*. Many properties files are used in java. It can be said that when writing java projects, configuration data is basically used *. this is also a configuration file officially supported by java. jdk provides ready-made APIs for operations.

When you use properties files in eclipse, the Chinese characters in the properties files are converted into asc codes by default. In this case, you can install a properties editor plug-in for eclipse to support Chinese display.

Properties editor plug-in: http://download.csdn.net/detail/abc_key/7482089

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.