博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java - properties read write
阅读量:4202 次
发布时间:2019-05-26

本文共 1944 字,大约阅读时间需要 6 分钟。

架构:

Get properties:

public static Properties getProperties(String fileName) {		String filePath = "src/resource/" + fileName + ".properties";		File pFile = new File(filePath);		FileInputStream pInStream = null;		try {            pInStream = new FileInputStream(pFile);        } catch (FileNotFoundException e) {            e.printStackTrace();        }        Properties p = new Properties();        try {            p.load(pInStream);         } catch (IOException e) {            e.printStackTrace();        }        // p.list(System.out);        return p;	}
取值:

public static void transform(Connection conn, ResultSet rs, String propertyName, String rawField, 			String newField) {		int score = 0;		Properties p = getProperties(propertyName);		Enumeration
enu = p.propertyNames(); while(enu.hasMoreElements()) { String thisKey = (String)enu.nextElement(); try { if (rawField.contains(thisKey)) { score = Integer.parseInt(p.getProperty(thisKey)); } } catch (NumberFormatException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } System.out.println(score); update(conn, rs, newField, score); }

写值:

public static void updateProperties(String fileName, List
updateList) { String filePath = "src/crawl/" + fileName + ".properties"; File pFile = new File(filePath); FileOutputStream pOutStream = null; try { pOutStream = new FileOutputStream(pFile); } catch (FileNotFoundException e) { e.printStackTrace(); } Properties p = new Properties(); try { for (String updateValue:updateList) { p.setProperty(updateValue,""); //key, value } p.store(pOutStream, null); pOutStream.close(); } catch (IOException e) { e.printStackTrace(); } }

参考:

http://blog.csdn.net/shixing_11/article/details/5652347

你可能感兴趣的文章
Pentaho BI开源报表系统
查看>>
andorid里关于wifi的分析
查看>>
Spring MVC 教程,快速入门,深入分析
查看>>
Ubuntu Navicat for MySQL安装以及破解方案
查看>>
在C++中如何实现模板函数的外部调用
查看>>
HTML5学习之——HTML 5 应用程序缓存
查看>>
HTML5学习之——HTML 5 服务器发送事件
查看>>
hbase shell出现ERROR: org.apache.hadoop.hbase.ipc.ServerNotRunningYetException
查看>>
解决Rhythmbox乱码
查看>>
豆瓣爱问共享资料插件发布啦
查看>>
kermit的安装和配置
查看>>
java中的异常机制
查看>>
商务智能-基本方法-数据钻取
查看>>
openstack-instance-high-availability-Evacuate
查看>>
evacuate-instance-automatically
查看>>
pycharm常用设置(keymap设置及eclipse常用快捷键总结)
查看>>
关于在openstack的环境变量.bashrc自定自己简化命令
查看>>
Openstack Heat Project介绍(转)
查看>>
How to Perform an Upgrade from Icehouse to Juno(ice升级到juno)
查看>>
高扩展性网站的50条原则(转)-思维导图
查看>>