package com.struts2.jquery.utils;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.apache.log4j.Logger;
/**
*
* <p>Title: crm</p>
*
* <p>Description: 操作属性配置文件工具类</p>
*
* <p>Copyright: Copyright (c) 2008</p>
*
* <p>Company: Newland</p>
*
* @author yaoxj
* @version 1.0 2008-12-26
*/
public final class PropertiesUtils
{
private static Logger log = Logger.getLogger(PropertiesUtils.class);
private static PropertiesUtils properUtils = null;
private static Properties prop = new Properties();
static
{
_load();
}
private PropertiesUtils() {
_load();
}
public static PropertiesUtils getInstance() {
_load();
return properUtils;
}
private static void _load() {
prop.clear();
InputStream ips=null;
try {
ips=getResourceAsStream("crm.properties");
prop.load(ips);
} catch (Exception e) {
log.error("无法载入属性配置文件!", e);
}finally{
try {
if(ips!=null){
ips.close();
ips=null;
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
private static InputStream getResourceAsStream(String resource) throws IOException {
InputStream in = PropertiesUtils.class.getClassLoader().getResourceAsStream(resource);
if(in == null){
in = ClassLoader.getSystemResourceAsStream(resource);
}
if(in == null){
in = new FileInputStream(resource);
}
if(in == null)
throw new IOException("无法读取资源文件: " + resource);
return in;
}
public static String getPropsValue(String key) { String value = "";
if (prop.containsKey(key))
value = prop.getProperty(key);
else
log.equals("属性文件中没有包含这个属性!");
return value;
}
public static String getPropsValue_Default(String key, String defaultValue)
{
return prop.getProperty(key, defaultValue);
}
}
转载请注明原文地址: https://ju.6miu.com/read-1308312.html