标签:
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; } }
标签:
原文地址:http://my.oschina.net/ysh3940/blog/379820