Java reads the configuration file (2)

Source: Internet
Author: User
package com.xxx.config;
Import Java. io. *; import Java. util. hashmap; import Java. util. map; import Java. util. properties;/*** read configuration integration class <br> * If the configuration source is not set, by default, xxxxxx configuration * @ author */public class configmanager {Private Static configs _ default = NULL; // Private Static hashmap configs = new hashmap (); private Static Boolean hasdefault = true;/*** get the configuration information of the specified configuration file * @ Param conf configuration file name * @ return configs object */public static configs getconfigs (St Ring module) {configs cf = NULL; // (configs) configs. get (module); If (cf = NULL) {configs df = getdefadefaconfigs (); If (df = NULL) return NULL; string file = DF. getconfig (module); If (file! = NULL & file. length ()> 0 & New Java. io. file (file ). isfile () {cf = new configs (); cf. init (file, DF. getconfigproperty ();} else {cf = DF;} // configs. put (module, CF);} return CF ;} /*** get the configuration information of the specified configuration file * @ Param conf configuration file name * @ return configs object */public static void setdefault (string module) {configs df = getdefaconfigconfigs (); if (df = NULL) return; string file = DF. getconfig (module); If (file! = NULL & file. length ()> 0 & New Java. io. file (file ). isfile () {configs cf = new configs (); cf. init (file, DF. getconfigproperty (); _ default = CF ;}} /*** get the configuration information of the specified configuration file * @ Param conf configuration file name * @ return configs object */public static void resetdefault () {_ default = NULL ;} /*** get the configuration value based on the configuration node name * @ Param key configure the node name * @ return configuration value */public static string getkey (string key) {return getkey (key, null, false );} /*** Get the configuration value based on the configuration node name * @ Param key configure the node name * @ Param defaul default value * @ return if there is a configuration value, the configuration value is returned, otherwise, the default value */public static string getkey (string key, string defaul) {return getkey (Key, defaul, false) is returned );} /*** get the configuration value based on the configuration node name * @ Param key configure the node name * @ Param islog whether to write logs. If it is true and the returned configuration value is null, write the log * @ return configuration value */public static string getkey (string key, Boolean islog) {return getkey (Key, null, islog);}/*** get the configuration value based on the configuration node name * @ Param key configure node name * @ Param defaul default value * @ Param islog whether to write logs. If it is true and the returned configuration value is null, write the log * @ return. If there is a configuration value, return the configuration value. Otherwise, return the default value */public static string getkey (string key, string defaul, Boolean islog) {configs cf = getdefaconfigconfigs (); If (CF! = NULL) return cf. getconfig (Key, defaul, islog); Return defaul;}/*** get the default configuration * @ return configs object */public static configs getdefaconfigconfigs () {If (_ default = NULL & hasdefault) {loaddefaconfig config () ;}return _ default;} static void loaddefaultconfig () {string F = ""; if (file. separatorchar = '\') F = "C: \ XXX. conf "; else f ="/xxx. conf "; system. out. println ("configuration file address" + F + "---------------------" ); File = new file (f); If (! File. isfile () {hasdefault = false; return ;}_ default = new configs (); _ default. INIT (f );}}

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.