From 628cdc9138a1179fe0f6ffdab4846fa40193107d Mon Sep 17 00:00:00 2001 From: user Date: Fri, 14 Mar 2025 23:52:25 +0800 Subject: [PATCH] =?UTF-8?q?refactor(web):=20=E4=BD=BF=E7=94=A8=20Path.of?= =?UTF-8?q?=20=E6=9B=BF=E4=BB=A3=20Paths.get?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/vxnet/pms/web/rest/FileUploadResource.java | 4 ++-- src/main/java/com/vxnet/pms/web/rest/UserResource.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/vxnet/pms/web/rest/FileUploadResource.java b/src/main/java/com/vxnet/pms/web/rest/FileUploadResource.java index 210d73d..0d34eb7 100644 --- a/src/main/java/com/vxnet/pms/web/rest/FileUploadResource.java +++ b/src/main/java/com/vxnet/pms/web/rest/FileUploadResource.java @@ -36,7 +36,7 @@ public class FileUploadResource { public Mono>> uploadFile(@RequestPart("file") FilePart file) { return Mono.fromCallable(() -> { // 确保上传目录存在 - Path uploadDir = Paths.get(uploadPath); + Path uploadDir = Path.of(uploadPath); if (!Files.exists(uploadDir)) { Files.createDirectories(uploadDir); } @@ -113,7 +113,7 @@ public class FileUploadResource { @GetMapping("/files/{filename:.+}") public Mono> getFile(@PathVariable String filename) { return Mono.fromCallable(() -> { - Path file = Paths.get(uploadPath).resolve(filename); + Path file = Path.of(uploadPath).resolve(filename); if (!Files.exists(file)) { return ResponseEntity.notFound().build(); } diff --git a/src/main/java/com/vxnet/pms/web/rest/UserResource.java b/src/main/java/com/vxnet/pms/web/rest/UserResource.java index 4c52d46..ccdc758 100644 --- a/src/main/java/com/vxnet/pms/web/rest/UserResource.java +++ b/src/main/java/com/vxnet/pms/web/rest/UserResource.java @@ -277,7 +277,7 @@ public class UserResource { String fileExtension = getFileExtension(filePart.filename()); String newFileName = UUID.randomUUID().toString() + fileExtension; String relativePath = "/" + newFileName; - Path uploadPath = Paths.get(avatarDir).toAbsolutePath().normalize(); + Path uploadPath = Path.of(avatarDir).toAbsolutePath().normalize(); Path filePath = uploadPath.resolve(newFileName).normalize(); try { @@ -293,7 +293,7 @@ public class UserResource { // 删除旧头像文件 if (user.getAvatar() != null) { try { - Path oldAvatarPath = Paths.get(avatarDir, new File(user.getAvatar()).getName()); + Path oldAvatarPath = Path.of(avatarDir).resolve(Path.of(user.getAvatar()).getFileName()); Files.deleteIfExists(oldAvatarPath); } catch (IOException e) {} }