In the application of the project, often put some configuration into the properties file, in the code application to read the properties file, you need a special class properties class, through this class can be read.
For further understanding and learning, see: In-depth understanding and learning properties Reference
This shows the Help class in the project that reads the properties configuration file, and the code can be used directly:
Importjava.io.IOException;Importjava.util.Properties; Public classpropertiesutil{ Public Static FinalString File_path = "Properties/upload.properties"; Get the corresponding value by passing in the path and key Public Staticstring GetValue (string path, String key) {Properties Properties=NewProperties (); Try{properties.load (propertiesutil).class. getClassLoader (). getResourceAsStream (path)); } Catch(IOException e) {Throw NewRuntimeException ("File Read Failed ...", E); } returnProperties.getproperty (key); }//Get the corresponding value directly via key Public Staticstring GetValue (String key) {Properties Properties=NewProperties (); Try{properties.load (propertiesutil).class. getClassLoader (). getResourceAsStream (File_path)); } Catch(IOException e) {Throw NewRuntimeException ("File Read Failed ...", E); } returnProperties.getproperty (key); }}
Properties class in Java and Read property values in attributes