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