From 5b98ae94350c48c3e70689d879911735ad27d5e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=A6=E9=B8=BF=E5=B1=95?= <18031053041@163.com> Date: Fri, 24 Jul 2026 19:42:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E5=85=A5=E7=89=A9=E6=96=99BUG?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MaterialBaseInfoApplicationService.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mhd_wms/src/main/java/com/mhd/wms/application/service/materialBaseInfo/MaterialBaseInfoApplicationService.java b/mhd_wms/src/main/java/com/mhd/wms/application/service/materialBaseInfo/MaterialBaseInfoApplicationService.java index 7dc41f623..b78ffebcd 100644 --- a/mhd_wms/src/main/java/com/mhd/wms/application/service/materialBaseInfo/MaterialBaseInfoApplicationService.java +++ b/mhd_wms/src/main/java/com/mhd/wms/application/service/materialBaseInfo/MaterialBaseInfoApplicationService.java @@ -457,7 +457,7 @@ public class MaterialBaseInfoApplicationService { throw new ServiceException("请上传xls或xlsx格式文件"); } - // 保存文件到临时目录 + // 流式写入临时文件,避免大文件 getBytes() 导致内存溢出和接口超时 String tmpDir = System.getProperty("java.io.tmpdir") + File.separator + "material_import"; File dir = new File(tmpDir); if (!dir.exists()) { @@ -465,8 +465,8 @@ public class MaterialBaseInfoApplicationService { } String tmpFileName = System.currentTimeMillis() + "_" + fileName; File tmpFile = new File(dir, tmpFileName); - try (FileOutputStream fos = new FileOutputStream(tmpFile)) { - fos.write(file.getBytes()); + try { + file.transferTo(tmpFile); } catch (Exception e) { throw new ServiceException("文件保存失败:" + e.getMessage()); }