JSP学习笔记(十五):读取properties配置文件的节点内容
在src目录建立p.properties配置文件,内容为:
str1=111111111
str2=222222222
str2=222222222
操作函数:
public String getContent() {
String content = "";
try {
Properties properties = new Properties();
InputStream is = getClass().getClassLoader().getResourceAsStream("p.properties");//加载p.properties文件内容
properties.load(is);//将文件内容装载到properties对象
is.close();
content = properties.getProperty("str1");//获取str1节点值
} catch (FileNotFoundException ex) {
} catch (IOException ex) {
}
return content;
}
String content = "";
try {
Properties properties = new Properties();
InputStream is = getClass().getClassLoader().getResourceAsStream("p.properties");//加载p.properties文件内容
properties.load(is);//将文件内容装载到properties对象
is.close();
content = properties.getProperty("str1");//获取str1节点值
} catch (FileNotFoundException ex) {
} catch (IOException ex) {
}
return content;
}

浙公网安备 33010602011771号