标签:
package com.pb.news.util;
import java.io.IOException;
import java.io.InputStream;
import java.sql.ResultSet;
import java.util.Properties;
//读取配置文件(属性文件)的工具类
public class ConfigManager {
private static ConfigManager configManager;
//properties.load(InputStream);读取属性文件
private static Properties properties;
private ConfigManager(){
String configFile="database.properties";
properties=new Properties();
InputStream in=ConfigManager.class.getClassLoader().getResourceAsStream(configFile);
try {
properties.load(in);
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
//通过单例模式设置实例化的个数
public static ConfigManager getInstance(){
if(configManager==null){
configManager=new ConfigManager();
}
return configManager;
}
//通过key获取对应的value
public String getString(String key){
return properties.getProperty(key);
}
}
//读取配置文件(属性文件)的工具类-ConfigManager
标签:
原文地址:http://www.cnblogs.com/JesseCary/p/4507611.html