PropertiesConfiguration--配置文件加载工具类

PropertiesConfiguration是一个配置文件的加载工具类,封装了从配置文件里获取值并转化为基本数据类型的方法。 它来自commons-configuration-1.6.jar。 直接上代码: [java] view plain copy public class Config { private static PropertiesConfiguration config = null; static { try { config = new PropertiesConfiguration( "config.properties"); } catch (ConfigurationException e) { e.printStackTrace(); } } public static String getString(String key) { return config.getString(key); } public static String getString(String key, String def) { return config.getString(key, def); } public static int getInt(String key) { return config.getInt(key); } public static int getInt(String key, int def) { return config.getInt(key, def); } public static long getLong(String key) { return config.getLong(key); } public static long getLong(String key, long def) { return config.getLong(key, def); } public static float getFloat(String key) { return config.getFloat(key); } public static float getFloat(String key, float def) { return config.getFloat(key, def); } public static double getDouble(String key) { return config.getDouble(key); } public static double getDouble(String key, double def) { return config.getDouble(key, def); } public static boolean getBoolean(String key) { return config.getBoolean(key); } public static boolean getBoolean(String key, boolean def) { return config.getBoolean(key, def); } public static String[] getStringArray(String key) { return config.getStringArray(key); } @SuppressWarnings("unchecked") public static List getList(String key) { return config.getList(key); } @SuppressWarnings("unchecked") public static List getList(String key, List def) { return config.getList(key, def); } public static void setProperty(String key, Object value) { config.setProperty(key, value); } } http://blog.csdn.net/majian_1987/article/details/11144335

猜你喜欢

转载自aoyouzi.iteye.com/blog/2285125