Read parameter file

xiaoxiao2021-03-06  65

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. Create a text file here, write: # Maximum user connection number ---- # is the comment MAX_CLIENT = 5 Good, save it to Storage.properties. Store in the program 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 ("user.dir"); - Get Project Path Name Prop.Load (New FileInputStream (Path File.Separator "Storage.properties")); - Load the proPeties file from the path of the project VALUE = Prop.GetProperty (PropName); - Get Parameter System .out.println ("Value =" value);} catch (filenotfoundexception fnfe) {system.out.println ("file /"storage.properties/" not found "); fnfe.printstacktrace ();} catch (ooException IOE) {IOE.PrintStackTrace ();} return value; well, if we want to change the value of Max_Client, just use Notepad's personality storage.properties, complete the source programs, no need to restart the server.

转载请注明原文地址:https://www.9cbs.com/read-119240.html

New Post(0)