属性文件读取
2016-05-18 11:01
239 查看
package com.common;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class AttributeOperate {
Log log;
private Properties pps;
public AttributeOperate(){
pps = new Properties();
log = LogFactory.getLog(AttributeOperate.class.getName());
}
public void setFilePath(String path){
if(null == path){
log.error("文件路径为空");
}else{
InputStream in;
try {
in = Object.class.getResourceAsStream(path);
pps.load(in);
} catch (FileNotFoundException e) {
log.error("the file "+path+" can't find!");
e.printStackTrace();
} catch (IOException e) {
log.error("the file "+path+" can't be load!");
e.printStackTrace();
}
}
}
public String getProperty(String key){
String value = pps.getProperty(key);
if(null == value){
log.debug(key+" 查询配置属性为空");
}
return value;
}
}
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class AttributeOperate {
Log log;
private Properties pps;
public AttributeOperate(){
pps = new Properties();
log = LogFactory.getLog(AttributeOperate.class.getName());
}
public void setFilePath(String path){
if(null == path){
log.error("文件路径为空");
}else{
InputStream in;
try {
in = Object.class.getResourceAsStream(path);
pps.load(in);
} catch (FileNotFoundException e) {
log.error("the file "+path+" can't find!");
e.printStackTrace();
} catch (IOException e) {
log.error("the file "+path+" can't be load!");
e.printStackTrace();
}
}
}
public String getProperty(String key){
String value = pps.getProperty(key);
if(null == value){
log.debug(key+" 查询配置属性为空");
}
return value;
}
}
相关文章推荐
- 预处理、编译、连接、运行
- FastDFS+Nginx轻量级分布式文件系统安装使用
- 关于java List的强制转型的理解
- java工程生成jar
- 使用Xcode和Instruments调试解决iOS内存泄露
- Spark standalone下的运行过程
- Spring常用注解,自动扫描装配Bean
- Android消息机制(Handler、MessageQueue、Looper)详细介绍
- 通过samba无法看到虚拟机linux里的文件
- csv下载功能整理
- 组织你的unity MonoBehaviours脚本
- android sensor架构
- QR分解-正交矩阵生成
- ScrollView嵌套ListView
- java 属性文件的读取操作
- Delphi-idHttp-JSON用法
- 史上最全“大数据”学习资源整理
- GIT入门学习1
- UITextField监听输入的文字
- 临沂市财政局四个立足 全面提高政府采购管理绩效