如下:
1、普通java项目:zhangsan=shandong
lisi=henan
此时,属性文件应该放在根目录下,而非src目录下,即:选中项目名字后粘贴属性文件Properties pro = new Properties();
//读取属性文件
InputStream in = new BufferedInputStream (new FileInputStream(""));
(in); ///加载属性列表
Iterator<String> it = ().iterator();
while(()){
String key=();
(key+":"+(key));
}
();
2、servlet中读取.properties文件
须将.properties文件放在WebContent目录下Properties properties = new Properties() ;
try {
FileInputStream fileInputStream = new FileInputStream(new File(("")+ "/" + ""));
(fileInputStream) ;
} catch (FileNotFoundException e1) {
();
}catch (IOException e) {
();
}