package com.framework.base.common.properties;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
*
* <p>读取属性公共类</p>
*/
public class CommonConfiguration {
private final static transient Log log = LogFactory.getLog(CommonConfiguration.class);
private final static Properties properties = new Properties() ;
static void init(){//D:\opt\froad\config\boss
FileInputStream fileInputStream = null;
try{
StringBuilder stringBuilder = new StringBuilder();
String separator = File.separator;
stringBuilder.append(separator).append("opt").append(separator).append("froad").append(separator).append("config")
.append(separator).append("boss").append(separator).append("context.properties");
fileInputStream = new FileInputStream(new File(stringBuilder.toString()));
properties.load(fileInputStream);
}catch (Exception e) {
log.error("-----------------加载properties失败---------------"+e.getMessage());
}finally{
if(fileInputStream != null){
try {
fileInputStream.close();
} catch (IOException e) {
fileInputStream = null;
}
}
}
}
public static void main(String args[]){
//init();
System.out.println("aaa:"+CommonConfiguration.getStrProperties("sysUrl"));
}
static{
init();
}
/**
* 获取value值
* @param key
* @return
* @param <E>
* @see
*/
public static String getStrProperties(String key) {
String value = properties.getProperty(key);
if(value == null ) {
value = "";
}
return value ;
}
/**
* 获取value值
* @param key
* @return
* @param <E>
* @see
*/
public static Integer getIntProperties(String key) {
String value = properties.getProperty(key);
if(value == null ) {
value = "10";
}
return Integer.valueOf(value) ;
}
}
读取属性公共类
最新推荐文章于 2021-02-24 09:48:36 发布