From 14ea071306f0ec3b79687346fa05116522f7a6a2 Mon Sep 17 00:00:00 2001
From: libin <17610879900@163.com>
Date: Sat, 08 May 2021 15:31:16 +0800
Subject: [PATCH] 修复文件上传时java.nio.file.FileAlreadyExistsException
---
ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUploadUtils.java | 20 ++++++++------------
1 files changed, 8 insertions(+), 12 deletions(-)
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUploadUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUploadUtils.java
index 183f918..daa9498 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUploadUtils.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUploadUtils.java
@@ -15,7 +15,7 @@
/**
* 文件上传工具类
- *
+ *
* @author ruoyi
*/
public class FileUploadUtils
@@ -89,7 +89,7 @@
*
* @param baseDir 相对应用的基目录
* @param file 上传的文件
- * @param extension 上传文件类型
+ * @param allowedExtension 上传文件类型
* @return 返回上传成功的文件名
* @throws FileSizeLimitExceededException 如果超出最大大小
* @throws FileNameLengthLimitExceededException 文件名太长
@@ -130,14 +130,10 @@
private static final File getAbsoluteFile(String uploadDir, String fileName) throws IOException
{
File desc = new File(uploadDir + File.separator + fileName);
-
- if (!desc.getParentFile().exists())
- {
- desc.getParentFile().mkdirs();
- }
- if (!desc.exists())
- {
- desc.createNewFile();
+ if (!desc.exists()) {
+ if (!desc.getParentFile().exists()) {
+ desc.getParentFile().mkdirs();
+ }
}
return desc;
}
@@ -215,7 +211,7 @@
/**
* 获取文件名的后缀
- *
+ *
* @param file 表单文件
* @return 后缀名
*/
@@ -228,4 +224,4 @@
}
return extension;
}
-}
\ No newline at end of file
+}
--
Gitblit v1.9.2