针对config.properties的配置文件读取的工具类
来源:互联网 发布:淘宝上的阿玛尼正品吗 编辑:程序博客网 时间:2024/06/18 14:04
针对config.properties的配置文件读取的工具类
拥有 getProperty(String key, String defaultValue)
getProperty(String key)
package com.guxiang.utils;import java.io.IOException;import java.io.InputStream;import java.util.Properties;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;/** * * 针对config.properties的配置文件读取类 * */public final class ConfigurableConstants { private static Log loger = LogFactory.getLog(ConfigurableConstants.class); private static Properties config_pro = new Properties(); private static String propertyFileName = "config/config.properties"; /** * 静态读入属性文件到Properties p变量中 */ static { loger.debug("初始化配置文件" + propertyFileName + "到 Constants...."); InputStream in = null; try { in = ConfigurableConstants.class.getClassLoader() .getResourceAsStream(propertyFileName); if (in != null) { config_pro.load(in); } } catch (IOException e) { loger.error("初始化配置文件 " + propertyFileName + " 到 Constants 发生错误,请检查相关配置文件!" + e); } finally { if (in != null) { try { in.close(); } catch (IOException e) { loger.error("close " + propertyFileName + " error!"); } } } } /** * * 封装了Properties类的getProperty函数,使p变量对子类透明. * * @param key * property key. * @param defaultValue * 当使用property key在properties中取不到值时的默认值. * @return 属性值 */ public static String getProperty(String key, String defaultValue) { if (config_pro.getProperty(key)== null) { return defaultValue; }else{ return config_pro.getProperty(key); } } /** * * 封装了Properties类的getProperty函数,使p变量对子类透明. * * @param key * property key. * @return 属性值 */ public static String getProperty(String key) { return getProperty(key, null); }}
阅读全文
0 0
- 针对config.properties的配置文件读取的工具类
- 读取properties配置文件的工具类
- properties配置文件的读取工具类
- 读取properties配置文件的工具类
- 读取properties配置文件的工具类
- 配置文件读取的一种方法config.properties
- java 数据库读取工具类(读取config.properties配置文件)
- java 数据库读取工具类(读取config.properties配置文件)
- XMLUtil工具类读取XML或properties格式的配置文件
- 配置文件properties的读取
- properties配置文件的读取
- 数据库连接的config.properties配置文件
- 读取.properties配置文件工具类!!!
- 读取Properties配置文件工具类
- 读取配置文件properties工具类
- properties配置文件读取工具类
- 读取properties配置文件工具类
- 配置文件的读取(.config)
- oozie报错解决方案
- 关于phpcms最近有被黑的情况
- zcmu-1932
- python报错:TypeError: data type not understood
- Banner 内存 磁盘 缓存
- 针对config.properties的配置文件读取的工具类
- Oracle学习笔记 -- day02 本机连接虚拟机(远程机)中的oracle设置
- SQL必知必会(2) 2~6课
- 360内核切换
- spring配置文件中util:properties和context:property-placeholder
- 蓝桥杯:01字串【水题】
- 3人3鬼过河问题
- [Robot OS]ROS机器人探索群资料列表(不定期更新)
- TabLayout