- 浏览: 71857 次
文章分类
- 全部博客 (47)
- 合并两个表 (1)
- java (46)
- 获得一个节点对象的节点类型 (1)
- JSP 页面不能解析EL表达式。 (1)
- 数据库连接长时间空闲后 (1)
- 爆连接已经关闭的解决方法 (1)
- 设计工作流引擎就象设计一部汽车(工作流程引擎设计思路提示) (1)
- Hadoop的下一代mapreduce (1)
- 备忘css元素定位 (1)
- 第一次通宵 (1)
- 字符编码工具类 (1)
- Asset Pipeline in rails 3.1.0 (1)
- IT行业热点----我国IT飞速发展需关注6大问题 (1)
- Web Service实践之——开始XFire (1)
- 单片机C语言编程基础模板 (1)
- 中医养生顺口溜 (1)
- Property文件读取的Util类 (1)
- JEECMS (1)
- CheckStyle使用java.header文件的问题 (1)
- JUnit4测试代码示例 (1)
- JavaScript中三个弹出窗口 (1)
- About .Net Petshop (1)
- MapXtreme2004代码 在地图上新增加点图元 (1)
- 50个GMail的邀请权 想要的留下EMail (1)
- asp.net+Access简单企业站源码 (1)
- 局域网指定ip断网工具源码 (1)
- lucene索引和搜索过程中的核心类介绍 (1)
- poi 取消科学计数法 (1)
- centos相关 (1)
- java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered (1)
- Project configuration is not up-to-date with pom.xml. 问题解决 (1)
- js截取最后一个.的字符串(IP地址判断) (1)
- Android开发之《Android应用开发揭秘》UI事件汇总 (1)
- SSH through proxy to visit ssh.github.com (ZZ) (1)
- eclipse3.7 添加任务标记 (1)
- SQLServer2005和2008的分页技术比较 (1)
- 传智播客java基础加强ppt (1)
- Struts 标签疑难问题收集-乔乐共享 (1)
- mysql使用rand随机查询记录效率测试 (1)
- 按钮实现spinner (1)
- 线程循环 (1)
- Android相关工具地址 (1)
最新评论
-
543089122:
N年前的老掉牙的手段了,原理也就是ARP
局域网指定ip断网工具源码 -
lvwenwen:
...
Web Service实践之——开始XFire -
hz_grape:
程序员的人生
第一次通宵 -
faylai:
传说中的广告贴啊!!
设计工作流引擎就象设计一部汽车(工作流程引擎设计思路提示)
Property文件以字符串形式保存数据。
这个类可以从Property文件中读取各种转换后的常见对象,可以继续扩展。
<textarea cols="50" rows="15" name="code" class="java">package com.arui.util;
import java.io.File;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
import java.util.TimeZone;
public class PropertiesUtil extends Properties {
private static final long serialVersionUID = -1810519669397594359L;
/**
* Default constructor.
*/
public PropertiesUtil() {
}
/**
* Load existing property.
*/
public PropertiesUtil(final Properties prop) {
super(prop);
}
/**
* Get boolean value.
*/
public boolean getBoolean(final String str) throws Exception {
String prop = getProperty(str);
if (prop == null) {
throw new Exception(str + " not found");
}
return prop.toLowerCase().equals("true");
}
/**
* Get boolean value.
*/
public boolean getBoolean(final String str, final boolean bol) {
try {
return getBoolean(str);
} catch (Exception ex) {
return bol;
}
}
/**
* Get integer value.
*/
public int getInteger(final String str) throws Exception {
String value = getProperty(str);
if (value == null) {
throw new Exception(str + " not found");
}
try {
return Integer.parseInt(value);
} catch (NumberFormatException ex) {
throw new Exception("PropertiesUtil.getInteger()", ex);
}
}
/**
* Get integer value.
*/
public int getInteger(final String str, final int intVal) {
try {
return getInteger(str);
} catch (Exception ex) {
return intVal;
}
}
/**
* Get long value.
*/
public long getLong(final String str) throws Exception {
String value = getProperty(str);
if (value == null) {
throw new Exception(str + " not found");
}
try {
return Long.parseLong(value);
} catch (NumberFormatException ex) {
throw new Exception("PropertiesUtil.getLong()", ex);
}
}
/**
* Get long value.
*/
public long getLong(final String str, final long val) {
try {
return getLong(str);
} catch (Exception ex) {
return val;
}
}
/**
* Get double value.
*/
public double getDouble(final String str) throws Exception {
String value = getProperty(str);
if (value == null) {
throw new Exception(str + " not found");
}
try {
return Double.parseDouble(value);
} catch (NumberFormatException ex) {
throw new Exception("PropertiesUtil.getDouble()", ex);
}
}
/**
* Get double value.
*/
public double getDouble(final String str, final double doubleVal) {
try {
return getDouble(str);
} catch (Exception ex) {
return doubleVal;
}
}
/**
* Get <code>InetAddress</code>.
*/
public InetAddress getInetAddress(final String str) throws Exception {
String value = getProperty(str);
if (value == null) {
throw new Exception(str + " not found");
}
try {
return InetAddress.getByName(value);
} catch (UnknownHostException ex) {
throw new Exception("Host " + value + " not found");
}
}
/**
* Get <code>InetAddress</code>.
*/
public InetAddress getInetAddress(final String str, final InetAddress addr) {
try {
return getInetAddress(str);
} catch (Exception ex) {
return addr;
}
}
/**
* Get <code>String</code>.
*/
public String getString(final String str) throws Exception {
String value = getProperty(str);
if (value == null) {
throw new Exception(str + " not found");
}
return value;
}
/**
* Get <code>String</code>.
*/
public String getString(final String str, final String s) {
try {
return getString(str);
} catch (Exception ex) {
return s;
}
}
/**
* Get <code>File</code> object.
*/
public File getFile(final String str) throws Exception {
String value = getProperty(str);
if (value == null) {
throw new Exception(str + " not found");
}
return new File(value);
}
/**
* Get <code>File</code> object.
*/
public File getFile(final String str, final File fl) {
try {
return getFile(str);
} catch (Exception ex) {
return fl;
}
}
/**
* Get <code>Class</code> object
*/
public Class<?> getClass(final String str) throws Exception {
String value = getProperty(str);
if (value == null) {
throw new Exception(str + " not found");
}
try {
return Class.forName(value);
} catch (ClassNotFoundException ex) {
throw new Exception("PropertiesUtil.getClass()", ex);
}
}
/**
* Get <code>Class</code> object
*/
public Class<?> getClass(final String str, final Class<?> cls) {
try {
return getClass(str);
} catch (Exception ex) {
return cls;
}
}
/**
* Get <code>TimeZone</code>
*/
public TimeZone getTimeZone(final String str) throws Exception {
String value = getProperty(str);
if (value == null) {
throw new Exception(str + " not found");
}
return TimeZone.getTimeZone(value);
}
/**
* Get <code>TimeZone</code>
*/
public TimeZone getTimeZone(final String str, final TimeZone tz) {
try {
return getTimeZone(str);
} catch (Exception ex) {
return tz;
}
}
/**
* Get <code>DateFormat</code> object.
*/
public SimpleDateFormat getDateFormat(final String str) throws Exception {
String value = getProperty(str);
if (value == null) {
throw new Exception(str + " not found");
}
try {
return new SimpleDateFormat(value);
} catch (IllegalArgumentException e) {
throw new Exception("Date format was incorrect: " + value, e);
}
}
/**
* Get <code>DateFormat</code> object.
*/
public SimpleDateFormat getDateFormat(final String str,
final SimpleDateFormat fmt) {
try {
return getDateFormat(str);
} catch (Exception ex) {
return fmt;
}
}
/**
* Get <code>Date</code> object.
*/
public Date getDate(final String str, final DateFormat fmt)
throws Exception {
String value = getProperty(str);
if (value == null) {
throw new Exception(str + " not found");
}
try {
return fmt.parse(value);
} catch (ParseException ex) {
throw new Exception("PropertiesUtil.getdate()", ex);
}
}
/**
* Get <code>Date</code> object.
*/
public Date getDate(final String str, final DateFormat fmt, final Date dt) {
try {
return getDate(str, fmt);
} catch (Exception ex) {
return dt;
}
}
/**
* Set boolean value.
*/
public void setProperty(final String key, final boolean val) {
setProperty(key, String.valueOf(val));
}
/**
* Set integer value.
*/
public void setProperty(final String key, final int val) {
setProperty(key, String.valueOf(val));
}
/**
* Set double value.
*/
public void setProperty(final String key, final double val) {
setProperty(key, String.valueOf(val));
}
/**
* Set float value.
*/
public void setProperty(final String key, final float val) {
setProperty(key, String.valueOf(val));
}
/**
* Set long value.
*/
public void setProperty(final String key, final long val) {
setProperty(key, String.valueOf(val));
}
/**
* Set <code>InetAddress</code>.
*/
public void setInetAddress(final String key, final InetAddress val) {
setProperty(key, val.getHostAddress());
}
/**
* Set <code>File</code> object.
*/
public void setProperty(final String key, final File val) {
setProperty(key, val.getAbsolutePath());
}
/**
* Set <code>DateFormat</code> object.
*/
public void setProperty(final String key, final SimpleDateFormat val) {
setProperty(key, val.toPattern());
}
/**
* Set <code>TimeZone</code> object.
*/
public void setProperty(final String key, final TimeZone val) {
setProperty(key, val.getID());
}
/**
* Set <code>Date</code> object.
*/
public void setProperty(final String key, final Date val,
final DateFormat fmt) {
setProperty(key, fmt.format(val));
}
/**
* Set <code>Class</code> object.
*/
public void setProperty(final String key, final Class<?> val) {
setProperty(key, val.getName());
}
}
</textarea>
发表评论
-
Android相关工具地址
2012-02-08 15:57 763SDK: http://developer.andr ... -
线程循环
2012-02-07 14:28 795@selector(xxxThread)方法以后,在方 ... -
按钮实现spinner
2012-02-03 12:43 855int cityID=0; //用于默认选择哪个 ... -
mysql使用rand随机查询记录效率测试
2012-02-03 09:24 732一直以为mysql随机查询几条数据,就用 SELECT ... -
Struts 标签疑难问题收集-乔乐共享
2012-02-02 15:14 848循环List:private List list; & ... -
传智播客java基础加强ppt
2012-01-31 16:13 1547<p>????? 如果想把java基础打牢 ... -
SQLServer2005和2008的分页技术比较
2012-01-31 15:53 1940<span style="fon ... -
eclipse3.7 添加任务标记
2012-01-31 15:23 2367<p>在编写程序时有一些工作要等到以后才做 ... -
SSH through proxy to visit ssh.github.com (ZZ)
2012-01-31 14:58 1871<p>Scenario:</p> ... -
Android开发之《Android应用开发揭秘》UI事件汇总
2012-01-11 14:43 1182<h1>Android开发之《Androi ... -
js截取最后一个.的字符串(IP地址判断)
2012-01-11 14:18 2228[size=small;] 由于我们的项目中需 ... -
Project configuration is not up-to-date with pom.xml. 问题解决
2012-01-11 13:09 2043<span>Project configu ... -
java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered
2011-12-28 12:28 5450<span style="font-f ... -
centos相关
2011-12-28 11:34 813比较新的源 rpm -Uvh http://dow ... -
poi 取消科学计数法
2011-12-21 13:33 2188[size=medium;]<br>[/s ... -
lucene索引和搜索过程中的核心类介绍
2011-12-21 12:54 1215lucene索引和搜索过 ... -
局域网指定ip断网工具源码
2011-12-20 13:53 2029只适用于小型局域网 <br> <s ... -
asp.net+Access简单企业站源码
2011-12-20 12:04 3152<span style="font-f ... -
50个GMail的邀请权 想要的留下EMail
2011-12-15 13:34 736今天看到自己已经有50个GMail的邀请权了 想要的请 ... -
MapXtreme2004代码 在地图上新增加点图元
2011-12-15 13:29 774sender, System.EventArgs e ...
相关推荐
JDK 内置的 Java.util.Properties 类为我们操作 .properties 文件提供了便利。 一. .properties 文件的形式 # 以下为服务器、数据库信息 dbPort = localhost databaseName = mydb dbUserName = root ...
import java.util.Properties; /** * @ProjectName : JavaTest * @PackageName : org.fenet.javamail * @FileName : PropertiyFileReader.java * @Describe : * @CreateTime : 2008-9-3下午04:07:01 * @...
用于读取.properties文件的可插拔Java Web应用程序插件 项目1:读取属性文件 建议不要在.java文件中存储服务器配置,例如数据库用户名,数据库密码,数据库IP地址,其他服务URL,FTP用户名,FTP密码和当前版本。 ...
配置文件的allow部分定义哪些类可以建立和转换,每个被准许的类都可以有一个'create'或者'convert'配置行.下面列出的类的转换在默认情况下不需要进一步的设置. 1、所有基本类型,boolean,int,double等等 2、基本类型...
import java.io.* ; import java.util.* ; public class Demo ... // 需要从文件中读取要Properties中的属性 p.loadFromXML(new FileInputStream("lxh.xml")) ; System.out.println(p) ; } };
其中第16行通过类路径的映射方式,将sshfile.model类包目录下的所有领域对象的映射文件装载进来,在本文的例子里,它将装载进Tfile.hbm.xml映射文件。如果有多个映射文件需要声明,使用类路径映射方式显然比直接...
2. Configuration.xml 里面 的是包含要映射的类的xml配置文件。 3. 在User.xml 文件里面 主要是定义各种SQL 语句,以及这些语句的参数,以及要返回的类型等. 开始测试 在test_src 源码目录下建立com.yihaomen.test...
在Android源码树中添加userspace I2C读写工具(i2c-util) 本文使用的开发板是:杭州若格科技有限公司的全志R8。CPU:CPUARM Cortex-A8 更多芯片资料请参见全志官网: http://www.allwinnertech.com/clq/r/R8.html...
finalize是Object类的一个方法,在垃圾收集器执行的时候会调用被回收对象的此方法,可以覆盖此方法提供垃圾收集时的其他资源回收,例如关闭文件等。 13、sleep() 和 wait() 有什么区别? sleep是线程类(Thread)的...
System.out.println("读取配置文件/config.properties出错"); } } /** * 程序总入口 */ private void start() { for(int i = 0; i (); i++) { URLConnection con = getConnection(configList.get(i)); ...
这个Demo体现shiro的地方主要在两个类以及shiro.xml的配置文件 CustomRealm : 处理了登录验证以及授权.. ShiroAction : 用来传递登录时的用户数据..转换为token传递给realm...之后根据结果做相应的逻辑处理.. shiro....
finalize是Object类的一个方法,在垃圾收集器执行的时候会调用被回收对象的此方法,可以覆盖此方法提供垃圾收集时的其他资源回收,例如关闭文件等。 16、sleep() 和 wait() 有什么区别? sleep是线程类(Thread)...
13.8. Spring对分段文件上传(multipart file upload)的支持 13.8.1. 介绍 13.8.2. 使用MultipartResolver 13.8.3. 在表单中处理分段文件上传 13.9. 使用Spring的表单标签库 13.9.1. 配置标签库 13.9.2. form标签 ...
7.4.4 数据集:ext.util.abstractmixedcollection与ext.util.mixedcollection / 330 7.4.5 数据验证及错误处理:ext.data.validations与ext.data.errors / 332 7.4.6 模型的关系:ext.data.association、ext.data...
Property 的 SOURCE 属性由 BlazeDS 读取 XML 配置文件获得: 清单 12. 配置 destination 的 id <destination id="flexService"> <properties> <factory>flexFactory</factory> <source>flexService...
Property 的 SOURCE 属性由 BlazeDS 读取 XML 配置文件获得: 清单 12. 配置 destination 的 id <destination id="flexService"> <properties> <factory>flexFactory</factory> <source>flexService...
4.4.4 Ext.util.Observable事件 4.4.5 Ext.EventManager事件 4.4.6 Ext.EventObject事件 4.5 各种事件登记方式 4.5.1 传统式登记 4.5.2 内联式登记 4.5.3 Dom Level2登记 4.6 高级组件事件 4.7 ExtJS键盘...
4.4.4 Ext.util.Observable事件 4.4.5 Ext.EventManager事件 4.4.6 Ext.EventObject事件 4.5 各种事件登记方式 4.5.1 传统式登记 4.5.2 内联式登记 4.5.3 Dom Level2登记 4.6 高级组件事件 4.7 ExtJS键盘...
System.err.println("不能读取属性文件. " + "请确保db.properties在CLASSPATH指定的路径中"); return; } String logFile = dbProps.getProperty("logfile", "DBConnectionManager.log"); try { log = new ...