package demo;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
/**
* 使用单例模式获取config.properties"里面的配置数据库连接配置信息
*/
@SuppressWarnings("WeakerAccess")
public class ConfigManager {
private static ConfigManager configManager; //定义一个自己的变量判断做返回使用
private static Properties properties;
private ConfigManager() {
//在构造方法里面得到配置对象
try {
String configFile = "config/config.properties";
properties = new Properties();
File file = new File(configFile);
if (!file.exists()){
System.out.println("config.properties" + "文件不存在!");
return;
}
InputStream is = new FileInputStream(file);