首页 > 编程语言 > 详细

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

时间:2015-02-25 11:45:31      阅读:317      评论:0      收藏:0      [点我收藏+]
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;
 }
}

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

原文:http://my.oschina.net/ysh3940/blog/379820

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!