- 浏览: 384022 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
消失-IT超市:
方便加一下你的QQ吗,我的QQ是252375879,有个问题请 ...
js调用ocx控件(读写IC卡) -
mszb00123:
很有用
Extjs之--图片上传器 -
shouhouhuakai:
好崇拜,不错
URLConnection的连接、超时、关闭用法总结 -
wujierd:
写得好详细,学习了
URLConnection的连接、超时、关闭用法总结 -
paruke:
请问这个能加上图片旋转功能么 我试了一下 发现寻找中心点是个问 ...
Extjs之--图片浏览器
1、web项目中读properties文件,一般放到class根目录下web/WEB-INF/classes/
public static String FILE_PATH = "/comms.properties"; private InputStream inputFile; private Properties propertie; propertie = new Properties(); inputFile = getClass().getResourceAsStream(FILE_PATH); propertie.load(inputFile); inputFile.close();
2、向properties文件写入时,需要获取绝对路径才能写入操作
public void saveFile(String fileName, String description) { String filePath = getClass().getResource("/").getPath()+fileName; File file = new File(filePath); try { outputFile = new FileOutputStream(file); propertie.store(outputFile, description); outputFile.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException ioe){ ioe.printStackTrace(); } }
getClass().getResource("/").getPath() 为获取class的根目录
3、不过在web服务启动中,经常变动*.properties这种方式会重新加载web工程
package com.mts.util; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.Properties; /** * 读取properties文件 * */ public class PropertiesUtils { private Properties propertie; private InputStream inputFile; private FileOutputStream outputFile; public static String FILE_PATH = "/mts.properties"; /** * 初始化Configuration类 */ public PropertiesUtils() { propertie = new Properties(); } /** * 初始化Configuration类 * @param filePath 要读取的配置文件的路径+名称 */ public PropertiesUtils(String filePath) { propertie = new Properties(); try { inputFile = getClass().getResourceAsStream(filePath); propertie.load(inputFile); inputFile.close(); } catch (FileNotFoundException ex) { System.out.println("读取属性文件--->失败!- 原因:文件路径错误或者文件不存在"); ex.printStackTrace(); } catch (IOException ex) { System.out.println("装载文件--->失败!"); ex.printStackTrace(); } }//end ReadConfigInfo(...) /** * 重载函数,得到key的值 * @param key 取得其值的键 * @return key的值 */ public String getValue(String key) { if(propertie.containsKey(key)){ String value = propertie.getProperty(key);//得到某一属性的值 return value; } else return ""; }//end getValue(...) /** * 重载函数,得到key的值 * @param fileName properties文件的路径+文件名 * @param key 取得其值的键 * @return key的值 */ public String getValue(String fileName, String key) { try { String value = ""; inputFile = getClass().getResourceAsStream(fileName); propertie.load(inputFile); inputFile.close(); if(propertie.containsKey(key)){ value = propertie.getProperty(key); return value; }else return value; } catch (FileNotFoundException e) { e.printStackTrace(); return ""; } catch (IOException e) { e.printStackTrace(); return ""; } catch (Exception ex) { ex.printStackTrace(); return ""; } }//end getValue(...) /** * 清除properties文件中所有的key和其值 */ public void clear() { propertie.clear(); }//end clear(); /** * 改变或添加一个key的值,当key存在于properties文件中时该key的值被value所代替, * 当key不存在时,该key的值是value * @param key 要存入的键 * @param value 要存入的值 */ public void setValue(String key, String value) { propertie.setProperty(key, value); }//end setValue(...) /** * 将更改后的文件数据存入指定的文件中,该文件可以事先不存在。 * @param fileName 文件路径+文件名称 * @param description 对该文件的描述 */ public void saveFile(String fileName, String description) { String filePath = getClass().getResource("/").getPath() + fileName; File file = new File(filePath); try { outputFile = new FileOutputStream(file); propertie.store(outputFile, description); outputFile.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } } }
评论
2 楼
ghhpig
2010-12-01
小问题请假下,为什么我的默认路径是在eclipse的安装目录下的?如何解决呢?谢谢
1 楼
zhangyuqing052
2010-04-12
propertie.store(outputFile, description);
为什么往properties文件中写时会出现#开头?
Ex:
propertie.store(outputFile, "name=liuxi1024");
打开文件的结果是: #name = liuxi1024
帮忙解释一下,谢谢!
还有就是,怎么样直接往properties文件中写Map,需要自己重写方法吗?
为什么往properties文件中写时会出现#开头?
Ex:
propertie.store(outputFile, "name=liuxi1024");
打开文件的结果是: #name = liuxi1024
帮忙解释一下,谢谢!
还有就是,怎么样直接往properties文件中写Map,需要自己重写方法吗?
发表评论
-
不负时光,继续学习
2017-04-11 17:04 6024月,一年当中最好的时节,和风煦日春意浓; ... -
生活依旧,做好自己
2017-02-04 16:51 384新年开工第二天,工作之余翻看了电脑上以前的文 ... -
2016年最后一天随笔
2016-12-30 14:48 5582016年马上就要过去了,回顾过去的一年感 ... -
excel中汉字转拼音全拼和简拼
2016-09-12 11:45 1510一、汉字转全拼 1.启动Excel 2003(其它版本请仿 ... -
年底总结3-工作中遇到的错误及解决方式
2015-02-16 11:28 977在过去的一年工作中遇到的一些问题及解决方式,如下: -- ... -
数据库方面遇到的问题总结
2013-05-23 20:29 9511、mysql服务自动关闭处理方式 我的电脑 -> ... -
resin2.1.17报错:META-INF/c.tld:6 unknown element `xsi:schemaLocation' in `taglib'
2012-08-20 18:37 30361、问题描述 resin启动后,访问jsp页面 ... -
Extjs grid 合计
2012-05-31 14:28 18751、直接在客户端统计,动态的修改Grid 2、代码如下 ... -
mysql函数使用-字符串处理
2012-05-29 17:15 11351、按地区统计数据 select q.psn,t.na ... -
spring JdbcTemplate 批量插入
2012-05-27 09:13 19921、通过批量操作减少与数据库连接所消耗的资源。 2、J ... -
JDBC连接Sql server
2012-03-07 10:24 16661、采用微软提供的ms sql server jdbc dri ... -
java下将汉字转换为拼音
2012-01-15 18:06 11641、代码如下,不过有些汉字不支持,如:茜 import ... -
年底总结2-spring多线程任务调度
2012-01-01 13:55 54131、spring framework开发参考手册中第23掌& ... -
年底总结1-tomcat6使用中遇到的问题
2012-01-01 10:23 65451、tomcat6.0.18注册windows服务成功后,但是 ... -
VML应用-利用ECOTree绘制树形结构图
2011-10-29 17:57 63181、基本概念 VML的全称是Vector Markup La ... -
java串口编程-读取称重仪表中净重
2011-10-12 17:08 5078一、需求说明 ... -
记录oracle 关联更新的例子
2011-10-03 20:55 11181、说明 修改某一天“本期值”数据时,需要把第二天的“上期值 ... -
js--设为首页、加入收藏
2011-03-19 00:13 944<a onclick="this.style. ... -
org.hibernate.ObjectNotFoundException: No row with the given identifier exists
2011-03-08 00:19 20461、问题说明 hibenate中实体关联映射中<man ... -
VirtualBox网络配置-搭建数据库服务器
2011-02-10 23:50 31171、由于操作系统与数据库之间兼容性的问题,于是采用在虚拟机上安 ...
相关推荐
帮助解决网页和JS文件中的中文编码问题的小工具 慎用const关键字 装箱,拆箱以及反射 动态调用对象的属性和方法——性能和灵活性兼备的方法 消除由try/catch语句带来的warning 微软的应试题完整版(附答案) 一个...
基于bootstrap实现的响应式Material Design风格的通用后台管理系统,`zheng`项目所有后台系统都是使用该模块界面作为前端展示。 > zheng-ui 各个子系统前台thymeleaf模板,前端资源模块,使用nginx代理,实现动静...
22.2 读写文件764 22.2.1 流764 22.2.2 Reader和Writer769 22.2.3 压缩流773 22.3 处理串行端口779 22.4 网络通信779 22.4.1 WebRequest和 WebResponse779 22.4.2 发送邮件786 22.5 小结787 第23章 用户控件、...
6.3.5 把文件内容从Stream对象移动到Byte数组中 175 6.4 MultiView和View服务器控件 175 6.5 Wizard服务器控件 179 6.5.1 定制边栏导航 181 6.5.2 AllowReturn属性 182 6.5.3 使用StepType属性 182 6.5.4 给...
动态INCLUDE用jsp:include动作实现 它总是会检查所含文件中的变化,适合用于包含动态页面,并且可以带参数。 静态INCLUDE用include伪码实现,定不会检查所含文件的变化,适用于包含静态页面...
upload.properties 如属性文件所描述,如图片想放到项目中,res.upload.url注释即可 7、缓存设置。为兼容jdk1.7,此版本中暂时废弃j2cache,默认仅使用ehcache缓存,如想使用,修改J2CacheUtil,用CacheJ2Utils替换...
启动项目,直接在浏览器中输入个人中心的路径,localhost:8081/userCenter。可以看到没报任何空指针错误,直接就进入了个人中心页面(当然要在同个浏览器中哦)。共享成功。 随后打开我们上次配置好的nginx,进入...
本书既可为广大的开发人员(不仅仅是Web应用程序开发人员)提供指导,也可为架构师的项目决策提供参考。项目经理、数据库管理员、质量保证员与测试员以及系统分析师也能从本书中受益。 目录: 第一部分 介绍 第1章 ...
动态INCLUDE用jsp:include动作实现 它总是会检查所含文件中的变化,适合用于包含动态页面,并且可以带参数。 静态INCLUDE用include伪码实现,定不会检查所含文件的变化,适用于包含静态页面...
jmeter.properties:Jmeter配置文件 jmeter-server.bat:windows下启动负载生成器服务文件 jmeter-server:Linux下启动负载生成器文件 /docs目录——Jmeter帮助文档 /extras目录——提供了对Ant的支持文件,可也用于...