First, the global configuration of simple Propertie file implementation
1 Packagecom.testgs.utils;2 3 ImportJava.util.*;4 ImportJava.io.*;5 6 7 Public Final classArconfig {8 9 PrivateProperties conf =NewProperties ();Ten PrivateString prefix = ""; One /** A * Global Profile name - */ - Public Static FinalString global_conf_file = "/analysisreportconfig.properties"; the - Publicarconfig (String prefix) { - This. prefix =prefix; - loadconf (); + } - + /** A * Get property File Instance at * @paramprefix each database connection prefix - * @return - */ - Public synchronized Staticarconfig getinstance (String prefix) { - return Newarconfig (prefix); - } in - Publicstring getconfstring (string name, String defaultvalue) { toString result =getconfstring (name); +result = (Result = =NULL) ?Defaultvalue:result; - returnresult; the } * $ /**Boolean value to read configuration informationPanax Notoginseng * @paramname - * @paramDefaultValue the * @return + */ A Public BooleanGetconfboolean (String name,BooleanDefaultValue) { the Booleanresult =DefaultValue; +String value =getconfstring (name); - if(Value! =NULL) { $Value =value.tolowercase (); $result = Value.equalsignorecase ("true") | | Value.equalsignorecase ("Yes"); - } - returnresult; the } - Wuyi /**Boolean value for reading configuration information, False if not, default the * @paramname - * @return Wu */ - Public BooleanGetconfboolean (String name) { About returnGetconfboolean (Name,false); $ } - - /** - * Read int value of configuration information A * @paramname + * @paramDefaultValue the * @return - */ $ Public intGetconfigint (String name,intDefaultValue) { theString Intv =getconfstring (name); the intresult =DefaultValue; the if(Intv! =NULL) { the Try { -result =Integer.parseint (Intv.trim ()); in}Catch(Exception e) { the e.printstacktrace (); the } About } the returnresult; the } the + Publicstring getconfstring (string name) { -Name = This. prefix +name; the returnConf.getproperty (name);Bayi } the the protected synchronized voidloadconf () { - conf.clear (); -InputStream input =NULL; the Try { theinput = This. GetClass (). getResourceAsStream (global_conf_file); the conf.load (input); the}Catch(IOException e) { - Throw NewRuntimeException ("Configuration File not found:" +global_conf_file); the}finally { the if(Input! =NULL) the Try {94 input.close (); the}Catch(Exception closee) { the } the }98 } About}accessing the properties file
Update in ...
Java Access configuration file summary