/**
* 读取配置文件
*/
import java.io.File;
import java.net.URL;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationFactory;
public class ConfigHelper {
public ConfigHelper(){
}
/**
* 读取配置文件
* @param strfile
* @return
*/
public static Configuration getConfig(String strfile){
Configuration config = null;
try {
ConfigurationFactory factory = new ConfigurationFactory(strfile);
config = factory.getConfiguration();
} catch (Exception e) {
e.printStackTrace();
}
return config;
}
/**
* @param args
*/
public static void main(String[] args) {
try{
Configuration config = getConfig("config.xml");
String backColor = config.getString("colors.background");
System.out.println("color: " + backColor);
config = null;
}catch(Exception e){
e.printStackTrace();
}
}
}