读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 ...
随机推荐
- Extjs3.3 + swfUpload2.2 实现多文件上传组件
[该上传组件已经停止更新,该上传组件已经在项目中使用.在使用过程中如果发现bug请大家回复此贴.2011-02-27] 主要是为了用swfUpload实现上传,为了新鲜好玩. 理解swfUpload可 ...
- 【wikioi】1217 借教室
题目链接http://www.wikioi.com/problem/1217/ 算法:二分答案(线段树可过wikioi数据) 二分:http://www.wikioi.com/solution/lis ...
- u盘文件系统故障的修复方法
比如U盘挂载的文件系统是/dev/sda1,且文件系统有故障(FAT: Filesystem error) 修复U盘文件系统故障 sudo dosfsck -v -a /dev/sda1
- winform学习之----打开文件对话框并将文件内容放入文本框
OpenFileDialog ofg = new OpenFileDialog(); ofg.Title = "ddd";//设置对话框标题 ofg.Multiselect = t ...
- ASP.NET MVC4系列验证机制、伙伴类共享源数据信息(数据注解和验证)
一,mvc前后台验证 自定义属性标签MyRegularExpression using System; using System.Collections.Generic; using System.C ...
- PHP下利用PHPMailer配合QQ邮箱下的域名邮箱发送邮件(转)
首先确定不是开启socks openssl phpinfo就可以知道 下载phpmailer 地址:https://github.com/PHPMailer/PHPMailer 下载完整, 个人和 ...
- C#中的托管堆和堆栈
托管堆(Heap)和堆栈(Stack)是内存的逻辑划分. 栈 堆 连续性 连续 不连续 有序性 后进先出 无序 内存管理 操作系统自动释放 GC或人工 存放类型 值类型/引用 引用类型 注:内存格 ...
- DX11.2 Tiled Resource Pool
Nvidia white paper : https://developer.nvidia.com/content/taking-advantage-directx112-tiled-resource ...
- 10. 求N分之一序列前N项和
求N分之一序列前N项和 #include <stdio.h> int main() { int i, n; double item, sum; while (scanf("%d& ...
- PHP 设计模式 笔记与总结(1)命名空间 与 类的自动载入
① PHP 面向对象高级特性 ② 11 种 PHP 设计模式 ③ PSR-0,Composer,Phar 等最流行的技术 目标是掌握 PHP 各类设计模式,以及具备设计纯面向对象框架和系统的能力 [命 ...