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文件的更多相关文章

  1. outlook——还原“未读邮件”文件夹

    参考链接:http://office.microsoft.com/zh-cn/outlook-help/HA010283248.aspx 摘抄: 还原“未读邮件”文件夹 全部显示 全部隐藏 “未读邮件 ...

  2. matlab文件操作及读txt文件(fopen,fseek,fread,fclose)

    文件操作是一种重要的输入输出方式,即从数据文件读取数据或将结果写入数据文件.MATLAB提供了一系列低层输入输出函数,专门用于文件操作. 1.文件的打开与关闭 1)打开文件 在读写文件之前,必须先用f ...

  3. MATLAB文件操作及读txt文件

    转自:http://blog.csdn.net/vblittleboy/article/details/8049748 文件操作是一种重要的输入输出方式,即从数据文件读取数据或将结果写入数据文件.MA ...

  4. read(),write() 读/写文件

    read read()是一个系统调用函数.用来从一个文件中,读取指定长度的数据到 buf 中. 使用read()时需要包含的头文件: <unistd.h> 函数原型: ssize_t re ...

  5. LinqToXML~读XML文件

    linq的出现,带给我们的是简结,快速,可读性,它由linq to sql,linq to object,linq to XML组成,我的博客之前有对linq to sql的讲解,而今天,我将讲一个l ...

  6. python中判断readline读到文件末尾

    fp = open('somefile.txt') while True: line = fp.readline() if not line: #等价于if line == "": ...

  7. C#、C++用GDAL读shp文件(转载)

    C#.C++用GDAL读shp文件 C#用GDAL读shp文件 (2012-08-14 17:09:45) 标签: 杂谈 分类: c#方面的总结 1.目前使用开发环境为VS2008+GDAL1.81 ...

  8. NOPI读xls文件写到txt中(NPOI系列二)

    private void button2_Click(object sender, EventArgs e) { StringBuilder sb = new StringBuilder(); //找 ...

  9. 用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 ...

随机推荐

  1. How far away[HDU2586]

    How far away ? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  2. Flo's Restaurant[HDU1103]

    Flo's Restaurant Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. UVA 10325 - The Lottery(容斥)

    以前做过的一个题,忘记/gcd了,看来需要把以前的东西看一下啊. #include <cstdio> #include <cstring> #include <iostr ...

  4. Contest Hunter Round #70 - 连续两大交易事件杯省选模拟赛

    orz lydrainbowcat [Problem A]「艦これ市」70万幕后交易事件 排序机器=-=.重要的是相同的处理. 我们可以从小到大添加数字,然后维护一个位置的序列.每一种相等的数字都在一 ...

  5. TAT,我的LCT转双旋了

    这里是rotate和splay函数 void rotate(int x) { ]==x; ch[y][d^]=ch[x][d];pre[ch[x][d]]=y; ch[z][ch[z][]==y]=x ...

  6. SqlServer主键外键添加及判断表是否存在

    GO --判断表是否存在方式1 if object_id(N'EF_User',N'U') is null --判断表是否存在方式2 --if not exists (select * from db ...

  7. 使用mybatis执行oracle存储过程

    存储过程在小公司用的不多,但是如果业务比较复杂或者性能要求比较苛刻的时候存储过程就派上用场了,ibatis的前期的一些版本貌似不支持存储过程因此我选择了mybatis来做实验. 1.无输入和输出参数的 ...

  8. 李洪强-C语言关键字、标识符和注释

    一.关键字 C语言提供的有特殊含义的符号,共32个. 在Xcode中关键字全部高亮显示,关键字全部都为小写.如return.int等. 二.标识符 定义:标识符是程序员在程序中自定义的一些符号和名称. ...

  9. hdu 猜数字

    这题的意思是找到最大的n使得m次之内的猜测可以猜到1~n之间的任何值.这里是二分思想的逆过程,1~h个数最多猜测log2(n+1)次(n为奇数),故 n=2^m-1; #include"io ...

  10. mysql中的comment用法

    转自:http://wenku.baidu.com/view/2a54e7892cc58bd63186bd8f.html 在MySQL数据库中,字段或列的注释是用属性comment来添加. 创建新表的 ...