在java程序中读取配置文件中的值
现象:
将某些参数写入配置文件 ,在Java程序中读取参数
方法:
(1):配置文件
(2):配置文件中的值
(3):使用方法读取配置文件中的值使用
(4):读取配置文件参数的方法
(5):读取配置文件参数方法的代码
/读取配置文件中的值
public static Object getParamFromProp(String key){
InputStream is=MyUtils.class.getClassLoader().getResourceAsStream("parameters.properties");
BufferedReader br= new BufferedReader(new InputStreamReader(is));
Properties props = new Properties();
try {
props.load(br);
return props.get(key);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
还没有评论,来说两句吧...