50 lines
1.4 KiB
Java
50 lines
1.4 KiB
Java
package com.tenwa.httpclient.resources;
|
|
|
|
import java.io.FileInputStream;
|
|
import java.io.FileNotFoundException;
|
|
import java.io.IOException;
|
|
import java.net.URLDecoder;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.Properties;
|
|
|
|
/**
|
|
* 1: ΢ÐÅÍÆËÍÏûÏ¢ÅäÖÃ
|
|
*/
|
|
public class WechatPropertiesUtil {
|
|
private static String CONFIG_FILE_NAME = "/Wechat.properties";
|
|
private static final Map<String, String> configMap = new HashMap<String, String>();
|
|
public static String getConfigValue(String propertyName) {
|
|
if (0 == configMap.size()) {
|
|
FileInputStream fis = null;
|
|
try {
|
|
fis = new FileInputStream(URLDecoder.decode(Thread.currentThread().getContextClassLoader().getResource(CONFIG_FILE_NAME).getFile(),"UTF-8"));
|
|
Properties pro = new Properties();
|
|
pro.load(fis);
|
|
for (Object key : pro.keySet()) {
|
|
String valString = pro.get(key).toString().trim();
|
|
String keyString = key.toString();
|
|
configMap.put(keyString, valString);
|
|
}
|
|
} catch (FileNotFoundException e) {
|
|
e.printStackTrace();
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
} finally {
|
|
try {
|
|
if (null != fis) {
|
|
fis.close();
|
|
fis = null;
|
|
}
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
return configMap.get(propertyName);
|
|
}
|
|
public static void main(String[] args) {
|
|
System.out.println(WechatPropertiesUtil.getConfigValue("WechatMenuURL"));
|
|
}
|
|
}
|