1、配置文件 配置参数
2、设计模式(单例模式)
新建resource存放配置文件
配置文件
配置类
package cn.xyh.dao2;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class Readconfig {
static Properties properties ;
static {
properties = new Properties();
InputStream resourceAsStream = Readconfig.class.getClassLoader().getResourceAsStream("db.properties");
try {
properties.load(resourceAsStream);
String driver = properties.getProperty("driver");
System.out.println(driver);
} catch (IOException e) {
e.printStackTrace();
}
}
public static String getValue(String key){
String property = properties.getProperty(key);
return property;
}
}
私有化构造