增加properties配置支持并添加README.md使用说明

This commit is contained in:
veryben
2017-05-19 16:44:41 +08:00
parent 548d2fb999
commit ad4e33055b
7 changed files with 294 additions and 23 deletions
@@ -30,7 +30,7 @@ public class IniFileReader {
loadFromFile(conf_filename);
}
private static ClassLoader classLoader() {
public static ClassLoader classLoader() {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (loader == null) {
loader = ClassLoader.getSystemClassLoader();
@@ -38,6 +38,25 @@ public class IniFileReader {
return loader;
}
public static InputStream loadFromOsFileSystemOrClasspathAsStream(String filePath) {
InputStream in = null;
try {
// 优先从文件系统路径加载
if (new File(filePath).exists()) {
in = new FileInputStream(filePath);
//System.out.println("loadFrom...file path done");
}
// 从类路径加载
else {
in = classLoader().getResourceAsStream(filePath);
//System.out.println("loadFrom...class path done");
}
} catch (Exception ex) {
ex.printStackTrace();
}
return in;
}
/**
* get the config filename
*
@@ -128,18 +147,8 @@ public class IniFileReader {
}
private void loadFromFile(String confFilePath) throws IOException {
InputStream in = null;
InputStream in = loadFromOsFileSystemOrClasspathAsStream(confFilePath);
try {
// 优先从文件系统路径加载
if (new File(confFilePath).exists()) {
in = new FileInputStream(confFilePath);
//System.out.println("loadFrom...file path done");
}
// 从类路径加载
else {
in = classLoader().getResourceAsStream(confFilePath);
//System.out.println("loadFrom...class path done");
}
readToParamTable(in);
} catch (Exception ex) {
ex.printStackTrace();