If a Java Web project is running on a tomcat or other container, you can use the following method to get the input stream of the file
1. When the attribute file is placed under SRC
InputStream is = Thread.CurrentThread (). Getcontextclassloader (). getResourceAsStream ("Test.properties"); Properties P = new properties (); P.load (IS);
2. When a property file is placed under a package, such as: Com.test.config
InputStream is = Thread.CurrentThread (). Getcontextclassloader (). getResourceAsStream ("Test.properties"); Properties P = new properties (); P.load (IS);
For a Java project, use the following method to read the properties file
InputStream is = Thread.CurrentThread (). Getcontextclassloader (). getResourceAsStream ("com/test/config/ Test.properties "); Properties P = new properties (); P.load (IS);
If the property file is placed under a package, use Com/test/config/test.properties to
*.properties format of the file in Java or quite a lot of, can be said to write Java project as long as the configuration data will basically use *.properties to do, this is the official Java support of a configuration file, JDK provides a ready-made API to operate.
When you use the properties format file in Eclipse, by default the Chinese in the properties file is converted to ASC, and we can install a properties Editor plugin for Eclipse to support the Chinese display.
Address: http://blog.csdn.net/abc_key/article/details/46511259;
Read the configuration file in Java