读propert文件
PropertiesUtil.java
package utils; import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties; public class PropertiesUtil {
private static InputStream in;//=prop.class.getClassLoader().getResourceAsStream("resource/date.properties");
private static Properties props;
private static String filePath=PropertiesUtil.class.getClassLoader().getResource("resource/date.properties").getFile();//.getPath();
static{
props=new Properties(); try {
in=new BufferedInputStream(new FileInputStream(filePath));
props.load(in);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}catch (IOException e) {
e.printStackTrace();
}
}
public static String readStringValue(String key) {
return props.getProperty(key);
} public static int readIntValue(String key) {
return Integer.valueOf(props.getProperty(key));
} public static Float readFloatValue(String key) {
return Float.valueOf(props.getProperty(key));
} public static String[] readStringArray(String key,String regex) {
return props.getProperty(key).split(regex);
} /**
* @param args
*/
public static void main(String[] args) {
System.out.println(PropertiesUtil.readStringValue("aa"));
System.out.println(PropertiesUtil.readIntValue("age"));
System.out.println(PropertiesUtil.readFloatValue("fl"));
System.out.println(PropertiesUtil.readStringArray("aa",",")[1]);
} }
date.properties
#用来测试的
aa=1,2,3,4,54,54,5,43,5,32,3,4532,45
age=1
fl=1.1
public static boolean isNumeric(String str){
Pattern pattern = Pattern.compile("[0-9]*");
return pattern.matcher(str).matches();
}
String.format("%03d",Integer.valueOf(no2)+1);
读propert文件的更多相关文章
- outlook——还原“未读邮件”文件夹
参考链接:http://office.microsoft.com/zh-cn/outlook-help/HA010283248.aspx 摘抄: 还原“未读邮件”文件夹 全部显示 全部隐藏 “未读邮件 ...
- matlab文件操作及读txt文件(fopen,fseek,fread,fclose)
文件操作是一种重要的输入输出方式,即从数据文件读取数据或将结果写入数据文件.MATLAB提供了一系列低层输入输出函数,专门用于文件操作. 1.文件的打开与关闭 1)打开文件 在读写文件之前,必须先用f ...
- MATLAB文件操作及读txt文件
转自:http://blog.csdn.net/vblittleboy/article/details/8049748 文件操作是一种重要的输入输出方式,即从数据文件读取数据或将结果写入数据文件.MA ...
- read(),write() 读/写文件
read read()是一个系统调用函数.用来从一个文件中,读取指定长度的数据到 buf 中. 使用read()时需要包含的头文件: <unistd.h> 函数原型: ssize_t re ...
- LinqToXML~读XML文件
linq的出现,带给我们的是简结,快速,可读性,它由linq to sql,linq to object,linq to XML组成,我的博客之前有对linq to sql的讲解,而今天,我将讲一个l ...
- python中判断readline读到文件末尾
fp = open('somefile.txt') while True: line = fp.readline() if not line: #等价于if line == "": ...
- C#、C++用GDAL读shp文件(转载)
C#.C++用GDAL读shp文件 C#用GDAL读shp文件 (2012-08-14 17:09:45) 标签: 杂谈 分类: c#方面的总结 1.目前使用开发环境为VS2008+GDAL1.81 ...
- NOPI读xls文件写到txt中(NPOI系列二)
private void button2_Click(object sender, EventArgs e) { StringBuilder sb = new StringBuilder(); //找 ...
- 用python3读CSV文件,出现UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd0 in position 0: invalid con
使用pd.read_csv()读csv文件时,出现如下错误: UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xd0 in position ...
随机推荐
- windows phone7 豆瓣FM
HubTile参考了下,就做了一个豆瓣的FM应用 豆瓣的API在百度里查一下. 整个应用很简单,无非是解析豆瓣的JSON数据,然后读取,下载图片和歌单
- TYVJ P1002 谁拿了最多奖学金 Label:模拟 水
背景 NOIP2005复赛提高组第一题 描述 某校的惯例是在每学期的期末考试之后发放奖学金.发放的奖学金共有五种,获取的条件各自不同:1) 院士奖学金,每人8000元,期末平均成绩高于80分( ...
- 转:Web前端,高性能优化
高性能HTML 一.避免使用iframe iframe也叫内联frame,可将一个HTML文档嵌入另一个HTML文档中. iframe的好处是,嵌入的文档独立于父文档,通常也借此使浏览器模拟多线程.缺 ...
- 【wikioi】1282 约瑟夫问题
题目链接:http://www.wikioi.com/problem/1282/ 算法:线段树(名次树) 说明在代码里有了,直接上代码. #include <cstdio> using n ...
- Graph database_neo4j 底层存储结构分析(8)
3.8 示例1:neo4j_exam 下面看一个简单的例子,然后看一下几个主要的存储文件,有助于理解<3–neo4j存储结构>描述的neo4j 的存储格式. 3.8.1 neo4j ...
- MyEclipse10整合Axis2插件
1.下载axis2的eclipse插件 2.把下载好的两个插件包解压后放置myeclipse10安装目录下的dropins文件夹中 3.重启MyEclipse10后 File->New-> ...
- 运用正则表达式在Asp中过滤Html标签代码的四种不同方法
Function RemoveHTML(strHTML)Dim objregExp, Match, MatchesSet objRegExp = New RegexpobjRegExp.IgnoreC ...
- tableviewCell折叠状态2
// // LHQContentViewCell.h // 11 - 投资管理 - 李洪强 // // Created by vic fan on 16/4/12. // Copyright ...
- zabbix配置文件详解
Zabbix之配置文件详解 zabbix配置文件种类: zabbix_server配置文件zabbix_server.conf zabbix_proxy配置文件zabbix_proxy.conf ...
- 一种少见的跨目录写webshell方法
http://hi.baidu.com/kwthqquszlbhkyd/item/480716204cfa33c3a5275afa