PackageCom.jy.modules.util;ImportJava.io.InputStream;Importjava.util.Enumeration;ImportJava.util.HashMap;ImportJava.util.Map;Importjava.util.Properties;Importorg.apache.commons.lang.StringUtils;/*** * @description function Description: *@authorAuthor: Zhouzhiwei *@paramParameters: Singleton mode read configuration file only once * @createdate build Date: June 9, 2015 PM 5:55:35 * @projectname project name: CMS * @ Packageclass Package and class name: Com.jy.modules.util.SystemConfigUtil.java*/ Public classSystemconfigutil {Private StaticSystemconfigutil Systemconfigutil =NULL; Private Staticmap<string, string> promap =NewHashmap<string, string>(); @SuppressWarnings ("Rawtypes") PrivateSystemconfigutil ()throwsException {InputStream is=NULL; Try{Properties Pro=NewProperties (); is= GetClass (). getResourceAsStream ("/filesystem.properties");//by default in the root directoryPro.load (IS); Enumeration e=Pro.propertynames (); while(E.hasmoreelements ()) {Object Object=(Object) e.nextelement (); String value=(String) Pro.get (object); Promap.put (String) object, value); } } Catch(Exception E2) {e2.printstacktrace (); } finally { Try{is.close (); } Catch(Exception e) {e.printstacktrace (); } } } Public StaticMap<string, string>Getpromap () {returnPromap; } Public StaticSystemconfigutil getinstance ()throwsException {if(Systemconfigutil = =NULL) {Systemconfigutil=NewSystemconfigutil (); } return NULL; } @SuppressWarnings ("Static-access") Public StaticString GetValue (String mapkey)throwsexception{systemconfigutil m=systemconfigutil.getinstance (); Map Map=M.getpromap (); if(Stringutils.isnotblank (Mapkey)) {String key=(String) map.get (Mapkey); returnkey; } returnMapkey; } }
Singleton mode read configuration file is created only once