读取配置文件
来源:互联网 发布:coc野蛮人之王升级数据 编辑:程序博客网 时间:2024/06/05 14:23
import java.util.Properties;
import org.apache.log4j.LogManager;
private static String CONFIG_FILE = "lmk.properties";
static {
initialize();
}
private static void initialize() {
log.trace("Begin to intitialize ConfiguraitonManager...");
try {
configProps.load(ConfigurationManager.class.getResourceAsStream(CONFIG_FILE));
String loginConfigFile = configProps.getProperty(ConfigurationManager.LOGIN_CONFIG);
loginConfigFile = ConfigurationManager.class.getResource(loginConfigFile).getPath();
System.setProperty(ConfigurationManager.LOGIN_CONFIG,loginConfigFile);
String waspLocation = configProps.getProperty(ConfigurationManager.WSAP_LOCATION);
waspLocation = ConfigurationManager.class.getResource(waspLocation).getPath();
System.setProperty(ConfigurationManager.WSAP_LOCATION,waspLocation);
} catch (Exception e) {
log.error("Intitializing ConfiguraitonManager error: ", e);
System.exit(0);
}
log.trace("Finish intitializing ConfiguraitonManager.");
* Get the configured value as integer. If not correctly configured, return 0.
*
* @param configKey
* the key name
* @return the int value
*/
public static String getConfigValue(String configKey) {
String configValue = (String) configProps.getProperty(configKey);
log.debug("ConfigurationManager.getConfiguration("
+ configKey + ")");
log.debug("configValue=" + configValue);
return configValue;
}
public static int getConfigValueAsInt(String configKey) {
int intValue = 0;
try {
intValue = Integer.parseInt(getConfigValue(configKey));
} catch (NumberFormatException e) {
intValue = 0;
log.error("Incorrect int value configured for " + configKey);
}
return intValue;
}
public static boolean getConfigValueAsBoolean(String configKey){
boolean booleanValue = false;
booleanValue = Boolean.parseBoolean(getConfigValue(configKey));
return booleanValue;
}
}
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
private static Logger log = LogManager.getLogger(ConfigurationManager.class);
private static Properties configProps = new Properties();private static String CONFIG_FILE = "lmk.properties";
static {
initialize();
}
private static void initialize() {
log.trace("Begin to intitialize ConfiguraitonManager...");
try {
configProps.load(ConfigurationManager.class.getResourceAsStream(CONFIG_FILE));
String loginConfigFile = configProps.getProperty(ConfigurationManager.LOGIN_CONFIG);
loginConfigFile = ConfigurationManager.class.getResource(loginConfigFile).getPath();
System.setProperty(ConfigurationManager.LOGIN_CONFIG,loginConfigFile);
String waspLocation = configProps.getProperty(ConfigurationManager.WSAP_LOCATION);
waspLocation = ConfigurationManager.class.getResource(waspLocation).getPath();
System.setProperty(ConfigurationManager.WSAP_LOCATION,waspLocation);
} catch (Exception e) {
log.error("Intitializing ConfiguraitonManager error: ", e);
System.exit(0);
}
log.trace("Finish intitializing ConfiguraitonManager.");
}
* Get the configured value as integer. If not correctly configured, return 0.
*
* @param configKey
* the key name
* @return the int value
*/
public static String getConfigValue(String configKey) {
String configValue = (String) configProps.getProperty(configKey);
log.debug("ConfigurationManager.getConfiguration("
+ configKey + ")");
log.debug("configValue=" + configValue);
return configValue;
}
public static int getConfigValueAsInt(String configKey) {
int intValue = 0;
try {
intValue = Integer.parseInt(getConfigValue(configKey));
} catch (NumberFormatException e) {
intValue = 0;
log.error("Incorrect int value configured for " + configKey);
}
return intValue;
}
public static boolean getConfigValueAsBoolean(String configKey){
boolean booleanValue = false;
booleanValue = Boolean.parseBoolean(getConfigValue(configKey));
return booleanValue;
}
}
阅读全文
1 0
- 读取配置文件
- 读取 配置文件
- 读取配置文件
- 读取配置文件
- 配置文件读取
- 配置文件读取
- 读取配置文件
- 读取配置文件
- 读取配置文件
- 读取配置文件
- 读取配置文件
- 读取配置文件
- 读取配置文件
- 读取配置文件
- 读取配置文件
- 读取配置文件
- 配置文件读取
- 读取配置文件
- C++快速幂
- python下人脸检测
- Codeforces 835D Round #427 Div2D :回文串DP
- 设计模式-外观模式
- 20个非常有用的Java程序片段
- 读取配置文件
- 确定类型和表达式在编译期信息的模板技术
- 菱形继承
- 配置远程Linux云服务器+可视化工作环境+jupyter notebook
- 解决h5中iphone手机input输入框被顶部地址栏盖住
- 服务器源码安装Apache
- Android———Layout:LinearLayout
- effective c++:写出一个不抛出异常的swap函数
- Kotlin:包结构有那么点任性