NEWS-包名-baseTest-类名-ConfigManager

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);
}
}

上一篇:K8S集群搭建


下一篇:Java 读书笔记 (十) 循环