声微饭否

博客园 首页 新随笔 联系 订阅 管理
 jdbc抽取到工具类中:

public class CopyUtils {
private Properties properties;
private static CopyUtils copyUtils;
private CopyUtils(){
//通过构造方法来执行加载properites文件
try {
FileInputStream fis = new FileInputStream("database.properties" );
properties =new Properties();
properties.load(fis);
} catch (IOException e) {
e.printStackTrace();
}
}
public static synchronized CopyUtils getCopyUtils(){
if(copyUtils==null){
synchronized (CopyUtils.class){
copyUtils =new CopyUtils();
}
}
return copyUtils;
}
public String getValue(String key){
return properties.getProperty(key);
}
}
posted on 2020-08-05 21:18  声微饭否  阅读(101)  评论(0编辑  收藏  举报