Configuration
package edu.fzu.ir.util; import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.Properties; import org.apache.log4j.Logger; /**
* 读取配置文件的工具类
* 提供了静态读取配置文件的方法
* 改配置文件是放在每个worker节点�?
* worker启动时根据配置文件路径读取该配置文件
* @author hasee
*
*/
public class Configuration {
private static Logger logger = Logger.getLogger(Configuration.class);
private static Properties properties;
private Configuration() {} /**
* 通过配置文件的路径获取相关的配置,存储在properties中,worker每次启动时调用该方法
* @param confPath 配置文件的路�?
*/
public static void loadConfiguration(String confPath) {
//判断properties是否是空,如果不为空表示已经加载过配置文件,不需要再加载
if(properties==null) {
//利用InputStreamReader指定利用utf-8编码读取properties文件
//这样是为了解决配置文件中的中文乱码问�?
InputStream inputStream = null;
InputStreamReader isr = null;
try {
inputStream = new FileInputStream(new File(confPath));
isr = new InputStreamReader(inputStream, "UTF-8");
} catch (FileNotFoundException e) {
//文件未找到时,输出错误日志,并停止系�?
logger.error(e);
System.exit(0);
} catch (UnsupportedEncodingException e) {
logger.error(e);
System.exit(0);
}
properties = new Properties();
try {
//加载并存储到properties
logger.info("load configuration from : "+ confPath);
properties.load(isr);
logger.info("load succeed!");
} catch (IOException e) {
logger.error(e);
} finally {
//关闭资源
try {
if(inputStream != null) {
inputStream.close();
}
if(isr != null) {
isr.close();
}
} catch (IOException e) {
logger.error(e);
}
}
}
} /**
* 获取配置文件中某�?��配置�?若不存在返回null
* @param key 配置项的key�?
* @return
*/
public static String getProperties(String key) {
String s = null;
if(properties != null){
s = properties.getProperty(key);
}
return s;
}
}
Configuration的更多相关文章
- PhpStorm和WAMP配置调试参数,问题描述Error. Interpreter is not specified or invalid. Press “Fix” to edit your project configuration.
PhpStorm和WAMP配置调试参数 问题描述: Error. Interpreter is not specified or invalid. Press “Fix” to edit your p ...
- Apache2.4:AH01630 client denied by server configuration
问题说明:Apache服务总共有4个,是为了防止单点故障和负载均衡,负载均衡控制由局方的F5提供. 访问的内容在NAS存储上,现象是直接访问每个apache的服务内容都是没有问题,但是从负载地址过来的 ...
- Fedora 22中的Locale and Keyboard Configuration
Introduction The system locale specifies the language settings of system services and user interface ...
- ABP源码分析四:Configuration
核心模块的配置 Configuration是ABP中设计比较巧妙的地方.其通过AbpStartupConfiguration,Castle的依赖注入,Dictionary对象和扩展方法很巧妙的实现了配 ...
- External Configuration Store Pattern 外部配置存储模式
Move configuration information out of the application deployment package to a centralized location. ...
- SCVMM中Clone虚拟机失败显示Unsupported Cluster Configuration状态
在SCVMM进行虚拟机的Clone,虽然失败了,但是Clone出虚拟机却显示在SCVMM控制台的虚拟机的列表中,并且状态是Unsupported Cluster Configuration.无法修复, ...
- commons configuration管理项目的配置文件
Commons Confifutation commons configuration可以很方便的访问配置文件和xml文件中的的内容.Commons Configuration 是为了提供对属性文件. ...
- Elasticsearch Configuration 中文版
##################### Elasticsearch Configuration Example ##################### # This file contains ...
- Spark 官方文档(4)——Configuration配置
Spark可以通过三种方式配置系统: 通过SparkConf对象, 或者Java系统属性配置Spark的应用参数 通过每个节点上的conf/spark-env.sh脚本为每台机器配置环境变量 通过lo ...
- spring configuration 注解
org.springframework.context.annotation @annotation.Target({ElementType.TYPE}) @annotation.Retention( ...
随机推荐
- 使用ASP.NET Web Api构建基于REST风格的服务实战系列教程【外传】——Attribute Routing
系列导航地址http://www.cnblogs.com/fzrain/p/3490137.html 题外话:由于这个技术点是新学的,并不属于原系列,但借助了原系列的项目背景,故命名外传系列,以后也可 ...
- ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)--MySQL错误
MySQL错误整理: 错误一: ERROR (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/my ...
- yum配置文件详解
yum是什么: Yellow dog Updater, Modified主要功能是更方便的添加/删除/更新RPM包,自动解决包的倚赖性问题,它能便于管理大量系统的更新问题. yum特点:可以同时配置多 ...
- QT读写ini配置文件
/********下面是写ini文件*************************/ //Qt中使用QSettings类读写ini文件 //QSettings构造函数的第一 ...
- TextBox 英文文档
TextBox Extend from $.fn.validatebox.defaults. Override defaults with $.fn.textbox.defaults. The Tex ...
- Apple Pay
Apple Pay运行环境:iPhone6以上设备,操作系统最低iOS9.0以上,部分信息设置需要iOS9.2以上.目前还不支持企业证书添加. 环境搭建好后可以在模拟器上面运行,xcode7.2.1+ ...
- SASS的一些使用体会(安装-配置-开启firefox的调试)
对CSS预处理这个东西的看法,基本就是2种 第一种:不就是css吗,我会写就好了搞得那么复杂干嘛 第二种:感觉这个东西非常有必要,它规范了代码,使开发变得更轻松 好吧以前我是第一种,并且觉得又要配置环 ...
- vue-cli + webpack 多页面实例应用
关于vue.js vue.js是一套构建用户界面的 轻型的渐进式前端框架.它的目标是通过尽可能简单的 API 实现响应的数据绑定和组合的视图组件.使用vue可以给你的开发带来极致的编程体验. 关于vu ...
- MainData仿Backbone Model式 数据模型记录器
MainData仿Backbone Model式 数据模型记录器主要思想:将 数据记录处理 和 因为数据变化而产生的页面渲染 两者解耦, 让页面元素可以与数据进行关联绑定,杜绝因为遗忘或是逻辑复杂导致 ...
- sql中的常见的全局变量
select APP_NAME ( ) as w --当前会话的应用程序 select @@IDENTITY --返回最后插入的标识值 select USER_NAME() --返回用户数据库用户名 ...