Sometimes we need to write the value of certain parameters in the program outside of the program, allowing the program to read the parameter value from these files. In this way, we do not have to modify the source program when we change these parameter values.
First create a text file with Notepad, change the name .properties. Here new text files, write: # Maximum user connection number ---- # 是 注 注 MAX_CLIENT = 5
Ok, save it to Storage.properties. Store where you can access.
Then read this parameter value in the program:
String propName = "MAX_CLIENT"; string value = ""; proties prop = new profment (); try {string path = system.getProperty); - Get project path name Prop.Load (New FileInputStream " (Path File.seParator "Storage.properties")); - Load the proPeties file from the path of the project to the proPetiS file value = prop.getProperty (propName); - Get parameter value system.out.println ("Value =" value);} catch (filenotfoundexception fnfe) {system.out.println ("file /"storage.properties/" not found "); fnfe.printStackTrace ();} catch (ooException IoE) {ion (} catch (ooException ie) {IOE.PrintStackTrace (); } Return Value;
Ok, if we want to change the value of Max_Client, just use the notepad personality storage.properties, do not use the source program, no need to restart the server.