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. javascript reverse string

    var strReversed = str.split('').reverse().join(''); function: function reverse(str){ return str.spli ...

  2. 【BZOJ】2329: [HNOI2011]括号修复(splay+特殊的技巧)

    http://www.lydsy.com/JudgeOnline/problem.php?id=2329 和前一题一样,不就多了个replace操作吗.好,就打一下. 然后交上去wa了........ ...

  3. hdu Largest Rectangle in a Histogram

    这道题目是一道动态规划的题目,动态规划的点不在面积上,而在每个矩形可左右扩展的坐标上.找出每个矩形最左边和最右边比它高的矩形的下标,最后求面积即可: #include"stdio.h&quo ...

  4. ASP.NET WEB API的服务托管(Self-HOST)

    如果我们想对外发布RESTful API,可以基于ASP.NET来构建Restful APIs,但需要部署IIS吗?答案是不必.你可以把它托管到一个Windows Service.具体如何把WEB A ...

  5. 如何处理NBU Frozen Media

    https://support.symantec.com/en_US/article.TECH21473.html

  6. 如何删除 OpenStack Nova 僵尸实例

    转自:http://www.vpsee.com/2011/11/how-to-delete-a-openstack-nova-zombie-instance/ 前天强制重启一台 OpenStack N ...

  7. Powershell的内置变量

    ls Variable:     Name Value Description $     ? TRUE Status of last command ^     args System.Object ...

  8. JavaWEB前端向服务器端发送对象

    最近项目中需要做一个关于批量删除的功能,删除条件有多个,需要从页面全部传给后台服务器程序,单个的删除,可以拼接参数给url,服务器端获取参数后执行删除操作即可.但是批量删除多个,参数会很多,传递就有些 ...

  9. HDU 4031 Attack(线段树/树状数组区间更新单点查询+暴力)

    Attack Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) Total Sub ...

  10. 序列化各个类型成JSON XML实例

    LitJson组件序列化请参考http://www.cnblogs.com/leee/p/4437230.html XML序列化请参考http://www.cnblogs.com/leee/p/424 ...