From 8b019a4f4478f074e613426d990c3209841b84a6 Mon Sep 17 00:00:00 2001 From: gongzhenkun <1658878546@qq.com> Date: Fri, 24 Mar 2023 14:03:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=B8=8B=E8=BD=BD=E5=9B=BE?= =?UTF-8?q?=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ruoyi/common/utils/file/FileUtils.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUtils.java index 8f41381..0d26163 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUtils.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUtils.java @@ -117,23 +117,20 @@ public class FileUtils */ public static void urlResourceWriteBytes(List> filePathList, OutputStream os) throws IOException { -// InputStream fis = null; - BufferedInputStream buf = null; + BufferedInputStream bufIn = null; ZipEntry zipEntry = null; ZipOutputStream zipOutputStream = new ZipOutputStream(os); try { for(Map filePath:filePathList){ URL file = new URL(filePath.get("urlPath").toString()); -// fis = file.openStream(); - buf = new BufferedInputStream(file.openStream()); + bufIn = new BufferedInputStream(file.openStream()); zipEntry = new ZipEntry(filePath.get("downloadPath").toString()); zipOutputStream.putNextEntry(zipEntry); - byte[] b = new byte[1024]; - int length; - while ((length = buf.read(b)) > 0) + int length = 0; + while ((length = bufIn.read()) != -1) { - zipOutputStream.write(b, 0, length); + zipOutputStream.write(length); } } } @@ -145,8 +142,8 @@ public class FileUtils { zipOutputStream.closeEntry(); IOUtils.close(zipOutputStream); + IOUtils.close(bufIn); IOUtils.close(os); - IOUtils.close(buf); } }