📄 globalconfig.java
字号:
package uselocal;
import java.io.InputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
public class GlobalConfig {
private static final ThreadLocal<GlobalConfig> threadConfig=
new ThreadLocal<GlobalConfig>();
private Properties properties = new Properties();
private GlobalConfig(){
try{
//加载配置信息
InputStream in=getClass().getResourceAsStream("myapp.properties");
properties.load(in);
in.close();
}catch(IOException e){throw new RuntimeException("加载配置信息失败");}
}
public static GlobalConfig getInstance(){
GlobalConfig config=threadConfig.get();
if(config==null){
config=new GlobalConfig();
threadConfig.set(config);
}
return config;
}
public Properties getProperties() {
return properties;
}
public static void main(String args[]){
GlobalConfig config=getInstance();
}
}
/****************************************************
* 作者:孙卫琴 *
* 来源:<<Java面向对象编程>> *
* 技术支持网址:www.javathinker.org *
***************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -