`

java操作properties文件

    博客分类:
  • Java
 
阅读更多

在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");
}
} 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics