-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfigHelper.java
52 lines (48 loc) · 1.08 KB
/
ConfigHelper.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* 读取配置文件
*/
package com.gootrip.util;
import java.io.File;
import java.net.URL;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationFactory;
/**
* @author advance
*
*/
public class ConfigHelper {
public ConfigHelper(){
}
/**
* 读取配置文件
* @param strfile
* @return
*/
public static Configuration getConfig(String strfile){
Configuration config = null;
try {
ConfigurationFactory factory = new ConfigurationFactory(strfile);
// URL configURL = new File(strfile).toURL();
// factory.setConfigurationFileName(configURL.toString());
config = factory.getConfiguration();
} catch (Exception e) {
e.printStackTrace();
}
return config;
}
/**
* @param args
*/
public static void main(String[] args) {
//ConfigHelper ch = new ConfigHelper();
//ch.test();
try{
Configuration config = getConfig("config.xml");
String backColor = config.getString("colors.background");
System.out.println("color: " + backColor);
config = null;
}catch(Exception e){
e.printStackTrace();
}
}
}