📄 configmanager.java
字号:
package com.ktv.common;
import org.apache.log4j.Logger;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
/**
* @author Cxj
*
*/
public class ConfigManager {
private final static String configFile = "/config.properties";
private static Logger log = LogUtil.getLogger(ConfigManager.class);
private static ConfigManager theInstance = null;
private Properties theProperties = null;
private ConfigManager() {
super();
this.load();
}
public static synchronized ConfigManager getInstance() {
{
theInstance = new ConfigManager();
}
return theInstance;
}
private void load() {
InputStream is = ConfigManager.class.getResourceAsStream(configFile);
if (is == null) {
log.error("Can not find the configuration file \"" + configFile
+ "\" in the JAVA CLASSPATH");
return;
}
theProperties = new Properties();
try {
theProperties.load(is);
} catch (IOException e) {
log.error("There is IOException occurred when tried to read from name file "
+ configFile);
}
}
public Properties getConfig() {
return theProperties;
}
public String getConfigValue(String key) {
if (theProperties == null)
return null;
return theProperties.getProperty(key);
}
public String getConfigValue(String key, String defaultValue) {
if (theProperties == null)
return defaultValue;
return theProperties.getProperty(key, defaultValue);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -