Method One: You can pass the load () method of the Java.util.Properties class
1 |
InputStreamin=lnewBufferedInputStream(newFileInputStream(name)); |
2 |
Propertiesp=newProperties(); |
Method Two: Use spring to read the properties configuration file
Org.springframework.beans.factory.support.PropertiesBeanDefinitionReader
Method Three: Through the Getbundle () method of the Java.util.ResourceBundle class
1 |
ResourceBundle rb = ResourceBundle.getBundle(name, Locale.getDefault()); |
Method Four: Through the constructor of the Java.util.PropertyResourceBundle class
1 |
InputStream in = new BufferedInputStream( new FileInputStream(name)); |
2 |
ResourceBundle rb = new PropertyResourceBundle(in); |
Thanks to a method provided by @luochen1314
Version two:
ResourceBundle res = Resourcebundle.getbundle (baseName);
BaseName is the package path/file name (without suffix)
For example, the properties file is under the COM.TT package and the file name is Tt.properties
Then Basenamewei COM/TT/TT
Method Five: Use the getResourceAsStream () method of the class variable
1 |
InputStream in = JProperties. class .getResourceAsStream(name); |
2 |
Properties p = new Properties(); |
Method Six: The getResourceAsStream () method of Java.lang.ClassLoader obtained by Class.getclassloader ()
Previewing source code printing
1 |
InputStream in = JProperties. class .getClassLoader().getResourceAsStream(name); |
2 |
Properties p = new Properties(); |
Method Seven: Through the Getsystemresourceasstream () static method of the Java.lang.ClassLoader class
1 |
InputStream in = ClassLoader.getSystemResourceAsStream(name); |
2 |
Properties p = new Properties(); |
Method Eight: You can use the Javax.servlet.ServletContext getResourceAsStream () method in a servlet
1 |
InputStream in = context.getResourceAsStream(path); |
2 |
Properties p = new Properties(); |
Title, the properties configuration file is often used in projects, so what are the ways to read the properties configuration file?