Java Access configuration file summary

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.