From c75f0ebee8f551e5acc7d7d9965a8be9d6731767 Mon Sep 17 00:00:00 2001 From: wangwei <1610949092@qq.com> Date: Mon, 24 Mar 2025 10:27:22 +0800 Subject: [PATCH] =?UTF-8?q?3/24=20=E8=AF=BB=E5=8F=96=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=BC=98=E5=8C=961.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sync/SpsSyncDataController.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/api-admin/src/main/java/com/glxp/sale/admin/controller/sync/SpsSyncDataController.java b/api-admin/src/main/java/com/glxp/sale/admin/controller/sync/SpsSyncDataController.java index 2d270d4..37558d6 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/controller/sync/SpsSyncDataController.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/controller/sync/SpsSyncDataController.java @@ -40,6 +40,7 @@ import org.springframework.web.client.RestTemplate; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; +import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; @@ -268,19 +269,15 @@ public class SpsSyncDataController { private String readDataFile(String cacheFilePath) { // 读取文件数据 - try { - FileReader reader = new FileReader(cacheFilePath); - StringBuilder str = new StringBuilder(); - int data; - while ((data = reader.read()) != -1) { - str.append((char) data); + try (BufferedReader reader = new BufferedReader(new FileReader(cacheFilePath))) { + StringBuilder str = new StringBuilder(1024); + String line; + while ((line = reader.readLine()) != null) { + str.append(line); } - reader.close(); return str.toString(); - } catch (FileNotFoundException e) { - throw new RuntimeException("系统异常,未找到对应数据文件"); - } catch (IOException e) { - throw new RuntimeException(e); + } catch (IOException e) { // 3. 合并异常处理 + throw new RuntimeException("文件读取失败: " + e.getMessage(), e); } }