From cb90fd415a8db7a26bd7741710ffeecbf1530152 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=B5=B7?= <10402852@qq.com> Date: Wed, 16 Oct 2024 15:38:31 +0800 Subject: [PATCH] 'commit' --- .../com/dsideal/base/Util/CommonUtil.java | 21 ++---------------- .../java/com/dsideal/gw/Util/CommonUtil.java | 21 ++---------------- .../com/dsideal/resource/Util/CommonUtil.java | 22 +++---------------- 3 files changed, 7 insertions(+), 57 deletions(-) diff --git a/dsBase/src/main/java/com/dsideal/base/Util/CommonUtil.java b/dsBase/src/main/java/com/dsideal/base/Util/CommonUtil.java index f7195ab0..1b8b27d5 100644 --- a/dsBase/src/main/java/com/dsideal/base/Util/CommonUtil.java +++ b/dsBase/src/main/java/com/dsideal/base/Util/CommonUtil.java @@ -51,26 +51,9 @@ public class CommonUtil { * @return 文件内容 * @throws IOException */ - public static String txt2String(String path) throws IOException { + public static String txt2String(String path) { InputStream is = CommonUtil.class.getClassLoader().getResourceAsStream(path); - BufferedInputStream bis = null; - StringBuilder sb = new StringBuilder(); - try { - bis = new BufferedInputStream(is); - byte[] temp = new byte[1024]; - int len; - while ((len = bis.read(temp)) != -1) { - sb.append(new String(temp, 0, len, StandardCharsets.UTF_8)); - } - } finally { - if (bis != null) { - bis.close(); - } - if (is != null) { - is.close(); - } - } - return sb.toString(); + return IoUtil.read(is, "UTF-8"); } /** diff --git a/dsGw/src/main/java/com/dsideal/gw/Util/CommonUtil.java b/dsGw/src/main/java/com/dsideal/gw/Util/CommonUtil.java index 54434039..66001aac 100644 --- a/dsGw/src/main/java/com/dsideal/gw/Util/CommonUtil.java +++ b/dsGw/src/main/java/com/dsideal/gw/Util/CommonUtil.java @@ -41,26 +41,9 @@ public class CommonUtil { * @return 文件内容 * @throws IOException */ - public static String txt2String(String path) throws IOException { + public static String txt2String(String path) { InputStream is = CommonUtil.class.getClassLoader().getResourceAsStream(path); - BufferedInputStream bis = null; - StringBuilder sb = new StringBuilder(); - try { - bis = new BufferedInputStream(is); - byte[] temp = new byte[1024]; - int len; - while ((len = bis.read(temp)) != -1) { - sb.append(new String(temp, 0, len, StandardCharsets.UTF_8)); - } - } finally { - if (bis != null) { - bis.close(); - } - if (is != null) { - is.close(); - } - } - return sb.toString(); + return IoUtil.read(is, "UTF-8"); } /** diff --git a/dsRes/src/main/java/com/dsideal/resource/Util/CommonUtil.java b/dsRes/src/main/java/com/dsideal/resource/Util/CommonUtil.java index fc84e1c5..efab7156 100644 --- a/dsRes/src/main/java/com/dsideal/resource/Util/CommonUtil.java +++ b/dsRes/src/main/java/com/dsideal/resource/Util/CommonUtil.java @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.jfinal.kit.PathKit; import com.jfinal.kit.StrKit; +import cn.hutool.core.io.IoUtil; import com.jfinal.plugin.activerecord.Page; import com.jfinal.plugin.activerecord.Record; import org.apache.commons.codec.binary.Base64; @@ -48,26 +49,9 @@ public class CommonUtil { * @return 文件内容 * @throws IOException */ - public static String txt2String(String path) throws IOException { + public static String txt2String(String path) { InputStream is = CommonUtil.class.getClassLoader().getResourceAsStream(path); - BufferedInputStream bis = null; - StringBuilder sb = new StringBuilder(); - try { - bis = new BufferedInputStream(is); - byte[] temp = new byte[1024]; - int len; - while ((len = bis.read(temp)) != -1) { - sb.append(new String(temp, 0, len, StandardCharsets.UTF_8)); - } - } finally { - if (bis != null) { - bis.close(); - } - if (is != null) { - is.close(); - } - } - return sb.toString(); + return IoUtil.read(is, "UTF-8"); } /**