一、今天需要在properties文件中读取值
文件如下:default.properties
二、java代码中读取properties中的值
文件如下:default.properties
keyword.default.siteurL=http://www.baidu.com
keyword.default.sitename=测试网站
keyword.default.siteid=1
keyword.default.sitelogo=/images/logo.jpg
keyword.default.ad.ponsition0=000
keyword.default.ad.ponsition1=111
二、java代码中读取properties中的值
public String getDefaultValue(String key) {
Properties properties = new Properties();
InputStreamReader inputstream;
try {
inputstream = new InputStreamReader(this.getClass().getClassLoader().getResourceAsStream("default.properties"), "UTF-8");
properties.load(inputstream);
inputstream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
String value = properties.getProperty(key);
return value;
}