From c3c49a05c2aa34748f7bfc0011a68ddf9239c4e4 Mon Sep 17 00:00:00 2001 From: XCSDN Date: Sat, 16 Apr 2022 06:02:07 +0000 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=B8=80=E4=B8=AA=E5=8F=96?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=90=8D=E8=80=8C=E4=B8=8D=E5=B8=A6=E5=90=8E?= =?UTF-8?q?=E7=BC=80=E7=9A=84=E6=95=B4=E5=90=88=E6=96=B9=E6=B3=95,?= =?UTF-8?q?=E5=B9=B2=E5=87=80=E5=8F=88=E5=8D=AB=E7=94=9F=E5=95=8A=E5=85=84?= =?UTF-8?q?=E5=BC=9F=E4=BB=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ruoyi/common/utils/file/FileUtils.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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 6915a53a5..bde198762 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 @@ -17,6 +17,7 @@ import com.ruoyi.common.config.RuoYiConfig; 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; /** * 文件处理工具类 @@ -257,7 +258,7 @@ public class FileUtils /** * 获取名称 - * + * 例如: /profile/upload/2022/04/16/ruoyi.png, 返回: ruoyi.png * @param fileName 路径名称 * @return 没有文件路径的名称 */ @@ -272,4 +273,19 @@ public class FileUtils int index = Math.max(lastUnixPos, lastWindowsPos); return fileName.substring(index + 1); } + + /** + * 获取名称 + * 例如: /profile/upload/2022/04/16/ruoyi.png, 返回: ruoyi + * @param fileName 路径名称 + * @return 没有文件路径的名称 + */ + public static String getNameNotSuffix(String fileName) { + if (fileName == null) { + return null; + } + String baseName = FilenameUtils.getBaseName(fileName); + return baseName; + } + }