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;
}
}