From 8505fd410a8ae8dbc4dfb0395a8f840b17754638 Mon Sep 17 00:00:00 2001 From: guoshengxiong <1923636941@qq.com> Date: Wed, 14 May 2025 14:36:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8C=85=E5=A4=B4=E4=BB=8Emino=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E6=96=87=E4=BB=B6=EF=BC=8C=E5=88=9B=E5=BB=BA=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=A4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/zhgd/xmgl/util/MinioUtils.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/zhgd/xmgl/util/MinioUtils.java b/src/main/java/com/zhgd/xmgl/util/MinioUtils.java index 8892728fe..a93e767aa 100644 --- a/src/main/java/com/zhgd/xmgl/util/MinioUtils.java +++ b/src/main/java/com/zhgd/xmgl/util/MinioUtils.java @@ -19,6 +19,7 @@ import javax.annotation.PostConstruct; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; +import java.io.IOException; /** * @description: minio工具类 @@ -46,10 +47,21 @@ public class MinioUtils { */ public static File downloadFile(String path) { File file = new File(PathUtil.getBasePath() + "/" + path); + FileOutputStream stream = null; try { - HttpUtil.download(PathUtil.getDomain() + path, new FileOutputStream(file), true); - } catch (FileNotFoundException e) { + FileUtil.mkdir(file.getParentFile()); + stream = new FileOutputStream(file); + HttpUtil.download(PathUtil.getDomain() + path, stream, true); + } catch (Exception e) { log.error("" + e); + } finally { + if (stream != null) { + try { + stream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } } return file; }