获取配置文件类(记录代码.properties)

1,

.properties中key-value形式

propertiesUtil

public class PropertiesUtil {

public static String getValue(String key){
Properties prop=new Properties();
InputStream in=new PropertiesUtil().getClass().getResourceAsStream("/ .properties");
try {
prop.load(in);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return (String)prop.get(key);
}
}

2,

直接用IDao接口

(1)
InputStream is = IClearInfoDao.class.getResourceAsStream("/resources/jdbc.properties");
Properties ps = new Properties();

(2)
读取文件
ps.load(is);
(3)
ps.getProperty("ctg_sams_warn_order")读取配置文件中的key值,获取到value值


还有很多方法 ,可以自己查阅。。。。。啦啦啦!!!我就不写了!!!





猜你喜欢

转载自www.cnblogs.com/dhqz/p/11346234.html
今日推荐