java遍历properties文件操作指南

2022-10-20,,,,

java项目开发过程中,使用properties文件作为配置基本上是必不可少的,很多如系统配置信息,文件上传配置信息等等都是以这种方式进行保存。
同时学会操作properties文件也是java基础。
复制代码 代码如下:
public class propertiesutil {
public static map getfileio(string filename){
properties prop = new properties();
map propmap=new hashmap();
inputstream in = propertiesutil.class.getresourceasstream(filename);
try {
prop.load(in);
setkeyset = prop.keyset();
for (object object : keyset) {
string propvalue= prop.getproperty(object.tostring()).tostring();
propmap.put(object.tostring(), prop.getproperty(object.tostring()).tostring());
system.out.println(object.tostring()+" : "+propvalue);
}
} catch (ioexception e) {
e.printstacktrace();
}finally{
try {
in.close();
} catch (ioexception e) {
e.printstacktrace();
}
}
return null;
}
public static void main(string[] args) {
getfileio("/loginurl.properties");
}
}

《java遍历properties文件操作指南.doc》

下载本文的Word格式文档,以方便收藏与打印。