/*
* Power by www.xiaoi.com
*/
package com.eastrobot.util;
import java.util.List;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
/**
* @author eko.zhan
* @date Nov 14, 2014 2:35:56 PM
* @version 1.0
*/
public class PropertiesUtil {
private static PropertiesConfiguration config;
static {
try {
config = new PropertiesConfiguration("app.properties");
} catch (ConfigurationException e) {
e.printStackTrace();
}
}
/**
* 如果没有找到配置则返回空字符串
*
* @param key
* @return
*/
public static String getString(String key) {
return getString(key, "");
}
/**
* 如果没有找到配置则返回默认值
*
* @param key
* @return
*/
public static String getString(String key, String defaultValue) {
return config.getString(key, defaultValue);
}
/**
* ,分隔获取为List<String>
*
* @param key
* @return
*/
@SuppressWarnings("unchecked")
public static List<String> getList(String key) {
if (config.getString(key) == null) {
return null;
}
return config.getList(key);
}
}
读取配置文件工具类
最新推荐文章于 2020-08-08 23:58:09 发布