import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
/**
* 资源文件读取类
*
* @version 1.0
* @createDate 2012-8-20
* @modifyDate 2012-8-20
*/
public class PropertiesUtil {
private static final LogTrace log = new LogTrace("PropertiesUtil");
/**
* 读取一个属性文件
*
* @param propName
* 属性文件名称
* @return 返回属性文件
* @throws IOException
* IO异常
*/
public static Properties getProperties(String propName) throws IOException {
if (StringUtil.isEmpty(propName)) {
return null;
}
Properties p = null;
InputStream in = ClassLoader.getSystemResourceAsStream(propName);
try {
if (in == null) {
in = PropertiesUtil.class.getResourceAsStream(propName);
}
if (in == null) {
in = PropertiesUtil.class.getClassLoader().getResourceAsStream(propName);
}
p = getProperties(in);
} catch (Exception e) {
log.error(e.getMessage());
} finally {
in.close();
}
return p;
}
/**
* 读取一个属性文件
*
* @param in
* 文件流
* @return 返回属性文件
* @throws IOException
*/
private static Properties getProperties(InputStream in) throws IOException {
Properties p = new Properties();
if (in != null) {
p.load(in);
in.close();
}
return p;
}
}
资源文件读取类
最新推荐文章于 2022-10-12 17:00:32 发布