diff --git a/src/main/java/org/smart4j/framework/util/PropsUtil.java b/src/main/java/org/smart4j/framework/util/PropsUtil.java index 02143681dcca387b500874ef876e1f0047638a64..b2507f29a530a95b73f9b4c7c73cbe87915cc2f8 100644 --- a/src/main/java/org/smart4j/framework/util/PropsUtil.java +++ b/src/main/java/org/smart4j/framework/util/PropsUtil.java @@ -1,15 +1,12 @@ package org.smart4j.framework.util; -import java.io.IOException; -import java.io.InputStream; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Properties; -import java.util.Set; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.IOException; +import java.io.InputStream; +import java.util.*; + /** * 属性文件操作工具类 * @@ -24,31 +21,30 @@ public class PropsUtil { * 加载属性文件 */ public static Properties loadProps(String propsPath) { + if (StringUtil.isEmpty(propsPath)) { + throw new IllegalArgumentException(); + } + Properties props = new Properties(); InputStream is = null; try { - if (StringUtil.isEmpty(propsPath)) { - throw new IllegalArgumentException(); - } - String suffix = ".properties"; - if (propsPath.lastIndexOf(suffix) == -1) { - propsPath += suffix; - } - is = ClassUtil.getClassLoader().getResourceAsStream(propsPath); - if (is != null) { - props.load(is); - } - } catch (Exception e) { - logger.error("加载属性文件出错!", e); - throw new RuntimeException(e); - } finally { try { + String suffix = ".properties"; + if (propsPath.lastIndexOf(suffix) == -1) { + propsPath += suffix; + } + is = ClassUtil.getClassLoader().getResourceAsStream(propsPath); + if (is != null) { + props.load(is); + } + } finally { if (is != null) { is.close(); } - } catch (IOException e) { - logger.error("释放资源出错!", e); } + } catch (IOException e) { + logger.error("加载属性文件出错!", e); + throw new RuntimeException(e); } return props; } @@ -79,8 +75,8 @@ public class PropsUtil { /** * 获取字符型属性(带有默认值) */ - public static String getString(Properties props, String key, String defalutValue) { - String value = defalutValue; + public static String getString(Properties props, String key, String defaultValue) { + String value = defaultValue; if (props.containsKey(key)) { value = props.getProperty(key); } @@ -117,8 +113,8 @@ public class PropsUtil { /** * 获取布尔型属性(带有默认值) */ - public static boolean getBoolean(Properties props, String key, boolean defalutValue) { - boolean value = defalutValue; + public static boolean getBoolean(Properties props, String key, boolean defaultValue) { + boolean value = defaultValue; if (props.containsKey(key)) { value = CastUtil.castBoolean(props.getProperty(key)); }