private static Properties prop = new Properties();
static{
try {
//InputStream ins = getClass().getResourceAsStream("db.properties");
InputStream ins = Thread.currentThread().getContextClassLoader().getResourceAsStream("test/test/db.properties");
// InputStream ins = new FileInputStream("test/test/db.properties");
prop.load(ins);
} catch (IOException e) {
e.printStackTrace();
}
}
public static String getValueFromProperties(String key){
return prop.getProperty(key);
}
如上边的程序,静态变量和静态块的先后顺序能不能改变为什么??
static{
try {
//InputStream ins = getClass().getResourceAsStream("db.properties");
InputStream ins = Thread.currentThread().getContextClassLoader().getResourceAsStream("test/test/db.properties");
// InputStream ins = new FileInputStream("test/test/db.properties");
prop.load(ins);
} catch (IOException e) {
e.printStackTrace();
}
}
public static String getValueFromProperties(String key){
return prop.getProperty(key);
}
如上边的程序,静态变量和静态块的先后顺序能不能改变为什么??
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货