1 PackageOrg.konghao.basic.util;2 3 ImportJava.io.FileInputStream;4 Importjava.io.FileNotFoundException;5 Importjava.io.IOException;6 ImportJava.io.InputStream;7 Importjava.util.Enumeration;8 ImportJava.util.HashMap;9 ImportJava.util.Map;Ten ImportJava.util.Map.Entry; One Importjava.util.Properties; A - ImportOrg.apache.wicket.util.file.File; - Importorg.junit.Test; the - Public classPropertiesutil { - - Private StaticProperties Properties; + - PrivateString Proper_resource; + Public voidSetproper_resource (String proper_resource) { A This. Proper_resource =Proper_resource; at } - - PublicPropertiesutil (String proper_resource) { - This. Proper_resource =Proper_resource; - } - in PublicMap<string,string>getProperties () { -Properties =getinstance (); to Try { +InputStream InputStream = Propertiesutil.class. getClassLoader (). getResourceAsStream (Proper_resource); - properties.load (inputstream); the}Catch(IOException e) { * e.printstacktrace (); $ }Panax NotoginsengMap<string,string> RegMap =NewHashmap<string, string>(); -Regmap.put ("AppId", Properties.getproperty ("AppId")); theRegmap.put ("Appsecret", Properties.getproperty ("Appsecret")); +Regmap.put ("Base_url", Properties.getproperty ("Base_url")); ARegmap.put ("Weixin_token", Properties.getproperty ("Weixin_token")); the returnRegMap; + } - $ Public StaticProperties getinstance () { $ if(NULL==properties) { -Properties =NewProperties (); - } the returnproperties; - }Wuyi the Public StaticProperties LoadResource (String file) { -Properties =getinstance (); Wu Try { -InputStream InputStream = Propertiesutil.class. getClassLoader (). getResourceAsStream (file); About System.out.println (inputstream); $ if(Properties! =NULL){ - properties.load (inputstream); - } -}Catch(IOException e) { A e.printstacktrace (); + } the returnproperties; - } $ the Public Static voidMain (string[] args) { thePropertiesutil PU =NewPropertiesutil ("Weixin_basic.properties"); themap<string, string> propsmap =pu.getproperties (); the - for(Entry<string, string>Entry:propsMap.entrySet ()) { inSystem.out.println ("key:" + entry.getkey () + ", Value:" +Entry.getvalue ())); the } the AboutProperties Properties = LoadResource ("Weixin_basic.properties"); theSystem.out.println (Properties.getproperty ("AppId")); the } the}
Propertiesutil Read Config file tool class