您的位置:首页 > 编程语言 > Java开发

Java学习资料-Java最优单例模式

2015-02-25 00:00 92 查看
摘要: Java学习资料-Java最优单例模式

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.apache.log4j.Logger;
/**
* PropertiesUtil
*
* @author yangshenhui
*/
public class PropertiesUtil {
private static Logger logger = Logger.getLogger(PropertiesUtil.class);
private PropertiesUtil() {
}
private static class SingletonHolder {
private final static PropertiesUtil INSTANCE = new PropertiesUtil();
}
public static PropertiesUtil getInstance() {
return SingletonHolder.INSTANCE;
}
public Properties getProperties(String fileName) {
Properties Properties = new Properties();
InputStream inputStream = null;
try {
inputStream = PropertiesUtil.class.getClassLoader()
.getResourceAsStream(fileName);
Properties.load(inputStream);
} catch (IOException e) {
logger.error(e.getMessage(), e);
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
}
}
return Properties;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: