属性配置文件工具类
来源:互联网 发布:jiragn 类似的软件 编辑:程序博客网 时间:2024/05/16 06:17
package com.struts2.jquery.utils;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStream;import java.util.Properties;import org.apache.log4j.Logger;/** * * <p>Title: crm</p> * * <p>Description: 操作属性配置文件工具类</p> * * <p>Copyright: Copyright (c) 2008</p> * * <p>Company: Newland</p> * * @author yaoxj * @version 1.0 2008-12-26 */public final class PropertiesUtils{ private static Logger log = Logger.getLogger(PropertiesUtils.class); private static PropertiesUtils properUtils = null; private static Properties prop = new Properties(); static { _load(); } private PropertiesUtils() { _load(); } public static PropertiesUtils getInstance() { _load(); return properUtils; } private static void _load() { prop.clear(); InputStream ips=null; try {ips=getResourceAsStream("crm.properties");prop.load(ips);} catch (Exception e) {log.error("无法载入属性配置文件!", e);}finally{try {if(ips!=null){ips.close();ips=null;}} catch (IOException e) {e.printStackTrace();}} } private static InputStream getResourceAsStream(String resource) throws IOException { InputStream in = PropertiesUtils.class.getClassLoader().getResourceAsStream(resource); if(in == null){ in = ClassLoader.getSystemResourceAsStream(resource); } if(in == null){ in = new FileInputStream(resource); } if(in == null) throw new IOException("无法读取资源文件: " + resource); return in;} public static String getPropsValue(String key) { String value = ""; if (prop.containsKey(key)) value = prop.getProperty(key); else log.equals("属性文件中没有包含这个属性!"); return value; } public static String getPropsValue_Default(String key, String defaultValue) { return prop.getProperty(key, defaultValue); } }
0 0
- 属性配置文件工具类
- 读写类路径下自定义属性配置文件工具类
- Java获取配置文件的属性值通用工具类2
- java工具类开发之日期工具类DateUtils和读取属性配置文件工具类PropertiesUtils
- 读取配置文件工具类
- 配置文件Configuration工具类
- 配置文件工具类【ConfigTools】
- Jfinal 配置文件工具类
- 配置文件工具类
- 配置文件读取工具类
- 读取配置文件工具类
- 配置文件加载工具类
- 配置文件读取工具类
- 配置文件读取工具类
- java读取配置文件工具类
- PropertiesConfiguration--配置文件加载工具类
- property配置文件读取工具类
- JDBC配置文件和工具类
- visual studio 版本的区别
- Android之root手机之后用busybox找到我们需要删除的文件
- 寻找最近点对
- Apache UIMA(二):配置Eclipse来使用UIMA
- UICollectionView进阶(一)
- 属性配置文件工具类
- SetMsgHandled()
- 在linux下永久保存路由表的写法(Suse和Redhat)
- 入门lr
- Linux中的伪终端编程
- Android 6.0 新功能及主要 API 变更
- Mybatis缓存
- java编程思想--继承
- JAXB注解使用小结