From 8052c62406b4474d9840ca561558d38749f6519c Mon Sep 17 00:00:00 2001 From: gongzhenkun <1658878546@qq.com> Date: Tue, 28 Mar 2023 11:00:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96zip=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/common/utils/file/FileUtils.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 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 c48d6bf..0de682d 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 @@ -24,6 +24,8 @@ import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.uuid.IdUtils; import org.apache.commons.io.FilenameUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import sun.misc.BASE64Decoder; /** @@ -33,6 +35,8 @@ import sun.misc.BASE64Decoder; */ public class FileUtils { + private static final Logger logger = LoggerFactory.getLogger(FileUtils.class); + public static String FILENAME_PATTERN = "[a-zA-Z0-9_\\-\\|\\.\\u4e00-\\u9fa5]+"; /** @@ -210,17 +214,15 @@ public class FileUtils fileOut = new FileOutputStream(desc); zipOutputStream = new ZipOutputStream(fileOut); for(Map filePath:filePathList){ - URL file = new URL(filePath.get("urlPath").toString()); - bufIn = new BufferedInputStream(file.openStream()); - zipEntry = new ZipEntry(filePath.get("downloadPath").toString()); - zipOutputStream.putNextEntry(zipEntry); -// byte[] b = new byte[1024*4]; -// int length; -// while ((length = bufIn.read(b)) > 0) -// { -// zipOutputStream.write(b, 0, length); -// } - IOUtils.copy(bufIn,zipOutputStream); + try{ + URL file = new URL(filePath.get("urlPath").toString()); + bufIn = new BufferedInputStream(file.openStream()); + zipEntry = new ZipEntry(filePath.get("downloadPath").toString()); + zipOutputStream.putNextEntry(zipEntry); + IOUtils.copy(bufIn,zipOutputStream); + }catch (Exception ee){ + logger.error("downloadLocalZip方法图片下载失败,"+filePath.get("urlPath").toString()+"地址的图片访问失败",ee); + } } } catch (IOException e)