From 8bea4e8a59cf5d013ce3b7168e77cee599d261df Mon Sep 17 00:00:00 2001 From: Raod <1130305001@qq.com> Date: Thu, 3 Mar 2022 15:59:28 +0800 Subject: [PATCH] =?UTF-8?q?hotfix-----windows=E5=AF=BC=E5=85=A5=E5=A4=A7?= =?UTF-8?q?=E5=B1=8F=E4=B9=B1=E7=A0=81=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../template/gaea/business/util/FileUtil.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/util/FileUtil.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/util/FileUtil.java index 8a81f0c1..6fcdbacf 100644 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/util/FileUtil.java +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/util/FileUtil.java @@ -8,6 +8,7 @@ import org.springframework.web.multipart.MultipartFile; import java.io.*; import java.net.URL; import java.nio.channels.FileChannel; +import java.nio.charset.StandardCharsets; import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; import java.util.Enumeration; @@ -116,9 +117,11 @@ public class FileUtil { */ public static String readFile(File file) { BufferedReader reader = null; + InputStreamReader isr = null; StringBuilder sbf = new StringBuilder(); try { - reader = new BufferedReader(new FileReader(file)); + isr = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8); + reader = new BufferedReader(isr); String tempStr; while ((tempStr = reader.readLine()) != null) { sbf.append(tempStr); @@ -129,6 +132,13 @@ public class FileUtil { log.error("读文件失败", e); throw BusinessExceptionBuilder.build(ResponseCode.FAIL_CODE, e.getMessage()); } finally { + if (null != isr) { + try { + isr.close(); + } catch (IOException e) { + throw BusinessExceptionBuilder.build(ResponseCode.FAIL_CODE, e.getMessage()); + } + } if (reader != null) { try { reader.close();