您的位置:首页 > 其它

属性文件读取

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;

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: