package cn.test;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
public class AppConfig {
private static AppConfig inst;
public static AppConfig init() {
if (inst == null) {
inst = new AppConfig();
}
return inst;
}
public static final String[] PROPERTIES_PATH = new String[] { "/jdbc.properties" };
private Properties pros = new Properties();
private Map<String,Object> ctx = new HashMap<String, Object>();
private AppConfig() {
try {
for (int i = 0; i < PROPERTIES_PATH.length; i++) {
String propFile = PROPERTIES_PATH[i];
InputStream is =this.getClass().getResourceAsStream(propFile);
pros.load(is);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static String getProperty(String key) {
return inst.pros.getProperty(key);
}
public static String getProperty(String key,String defValue) {
return inst.pros.getProperty(key, defValue);
}
public static void putAttr(String key,Object value) {
inst.ctx.put(key, value);
}
public static Object getAttr(String key) {
return inst.ctx.get(key);
}
public static void main(String[] args) {
AppConfig.init();
String eamil=AppConfig.getProperty("jdbc.drive");
System.out.println(eamil);
}
}