标签:
package baseTest;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
//读取配置文件
public class ConfigManager {
private static ConfigManager config;
private static Properties pro;
//构造方法进行配置文件读取
private ConfigManager(){
String configFile="database.properties";
pro=new Properties();
InputStream in=ConfigManager.class.getClassLoader().getResourceAsStream(configFile);
try {
pro.load(in);
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//通过单列模式设置实力化个数
public static ConfigManager getInstance(){
if(config==null){
config=new ConfigManager();
}
return config;
}
//通过key获取对应的value
public String getString(String key){
return pro.getProperty(key);
}
}
NEWS-包名-baseTest-类名-ConfigManager
标签:
原文地址:http://www.cnblogs.com/JesseCary/p/4507595.html