📄 propertiesloaderutils.java
字号:
/**
*
* 功能 Coarse Function Description
* 类名 PropertiesLoaderUtils
*
* ver 变更日 部门 变更者 变更内容
* ──────────────────────────────────
* V1.0 2006-11-14 国内事业部 陈志武 初版
* V1.1 2006-11-14 国内事业部 陈志武 改定
*
*/
package com.hisoft.cottonbusiness.core.util;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.apache.log4j.Logger;
/**
* Class description in detail
*
*
* @author 陈志武
* @version Ver 1.0 2006-11-14 改订
* @since Ver 1.0
*/
public class PropertiesLoaderUtils {
private static final Logger log = Logger
.getLogger(PropertiesLoaderUtils.class);
public static Properties load(String[] cfg) {
if (null == cfg || cfg.length == 0) {
String msg = "please input configuration file!";
log.error(msg);
throw new RuntimeException(msg);
}
Properties props = new Properties();
try {
for (int i = 0; i < cfg.length; i++) {
if (i == 0) {
InputStream is = getContextClassLoader()
.getResourceAsStream(cfg[i]);
if (null != is) {
props.load(is);
}
} else {
InputStream is = getContextClassLoader()
.getResourceAsStream(cfg[i]);
Properties addedMap = new Properties();
if (null != is) {
addedMap.load(is);
}
props.putAll(addedMap);
}
}
return props;
} catch (IOException e) {
String msg = "cfg reading error: " + e.getMessage();
log.error(msg, e);
throw new RuntimeException(msg, e);
} catch (IllegalArgumentException e) {
String msg = "cfg file format error: " + e.getMessage();
log.error(msg, e);
throw new RuntimeException(msg, e);
}
}
public static Properties load(String cfg) {
String[] file = { cfg };
return load(file);
}
private static ClassLoader getContextClassLoader() {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
if (null == cl) {
cl = PropertiesLoaderUtils.class.getClassLoader();
}
return cl;
}
/**
* @param args
*/
public static void main(String[] args) {
String file = "global.properties";
Properties props = load(file);
String[] sql = StringUtils.getStrings(props.getProperty("sql"));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -