提交者
Gitee
新增一个取文件名而不带后缀的整合方法,干净又卫生啊兄弟们
正在显示
1 个修改的文件
包含
17 行增加
和
1 行删除
| @@ -17,6 +17,7 @@ import com.ruoyi.common.config.RuoYiConfig; | @@ -17,6 +17,7 @@ import com.ruoyi.common.config.RuoYiConfig; | ||
| 17 | import com.ruoyi.common.utils.DateUtils; | 17 | import com.ruoyi.common.utils.DateUtils; |
| 18 | import com.ruoyi.common.utils.StringUtils; | 18 | import com.ruoyi.common.utils.StringUtils; |
| 19 | import com.ruoyi.common.utils.uuid.IdUtils; | 19 | import com.ruoyi.common.utils.uuid.IdUtils; |
| 20 | +import org.apache.commons.io.FilenameUtils; | ||
| 20 | 21 | ||
| 21 | /** | 22 | /** |
| 22 | * 文件处理工具类 | 23 | * 文件处理工具类 |
| @@ -257,7 +258,7 @@ public class FileUtils | @@ -257,7 +258,7 @@ public class FileUtils | ||
| 257 | 258 | ||
| 258 | /** | 259 | /** |
| 259 | * 获取名称 | 260 | * 获取名称 |
| 260 | - * | 261 | + * 例如: /profile/upload/2022/04/16/ruoyi.png, 返回: ruoyi.png |
| 261 | * @param fileName 路径名称 | 262 | * @param fileName 路径名称 |
| 262 | * @return 没有文件路径的名称 | 263 | * @return 没有文件路径的名称 |
| 263 | */ | 264 | */ |
| @@ -272,4 +273,19 @@ public class FileUtils | @@ -272,4 +273,19 @@ public class FileUtils | ||
| 272 | int index = Math.max(lastUnixPos, lastWindowsPos); | 273 | int index = Math.max(lastUnixPos, lastWindowsPos); |
| 273 | return fileName.substring(index + 1); | 274 | return fileName.substring(index + 1); |
| 274 | } | 275 | } |
| 276 | + | ||
| 277 | + /** | ||
| 278 | + * 获取名称 | ||
| 279 | + * 例如: /profile/upload/2022/04/16/ruoyi.png, 返回: ruoyi | ||
| 280 | + * @param fileName 路径名称 | ||
| 281 | + * @return 没有文件路径的名称 | ||
| 282 | + */ | ||
| 283 | + public static String getNameNotSuffix(String fileName) { | ||
| 284 | + if (fileName == null) { | ||
| 285 | + return null; | ||
| 286 | + } | ||
| 287 | + String baseName = FilenameUtils.getBaseName(fileName); | ||
| 288 | + return baseName; | ||
| 289 | + } | ||
| 290 | + | ||
| 275 | } | 291 | } |
-
请 注册 或 登录 后发表评论