From 1302014467539583fc4be6058e6712cd60ef8e24 Mon Sep 17 00:00:00 2001 From: bysocket Date: Tue, 19 Jul 2016 22:43:47 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E6=96=B9=E6=B3=95=E7=BA=A7=E5=88=AB=20?= =?UTF-8?q?=E5=B1=82=E6=AC=A1=E7=BB=93=E6=9E=84=E4=BF=AE=E6=94=B9=202.=20I?= =?UTF-8?q?O=E6=93=8D=E4=BD=9C=E7=BC=A9=E5=87=8F=E4=BB=A3=E7=A0=81=20--=20?= =?UTF-8?q?=E6=9D=A5=E8=87=AA=20think=20in=20java=203.=20=E9=94=99?= =?UTF-8?q?=E5=88=AB=E5=AD=97=20#=20bysocket?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/smart4j/framework/util/PropsUtil.java | 52 +++++++++---------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/src/main/java/org/smart4j/framework/util/PropsUtil.java b/src/main/java/org/smart4j/framework/util/PropsUtil.java index 0214368..b2507f2 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)); } -- Gitee