From 7539cfea113776e2fe340e0e9a056efca70bd48f Mon Sep 17 00:00:00 2001 From: bwcx_jzy Date: Mon, 2 Aug 2021 10:11:24 +0800 Subject: [PATCH] =?UTF-8?q?=E8=83=BD=E9=81=87=E5=88=B0=E5=8F=AA=E8=AF=BB?= =?UTF-8?q?=E6=96=87=E4=BB=B6=EF=BC=8C=E6=97=A0=E6=B3=95=E5=88=A0=E9=99=A4?= =?UTF-8?q?.=E4=BD=BF=E7=94=A8=20file=20=E6=96=B9=E6=B3=95=E5=88=A0?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hutool-core/src/main/java/cn/hutool/core/io/FileUtil.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/hutool-core/src/main/java/cn/hutool/core/io/FileUtil.java b/hutool-core/src/main/java/cn/hutool/core/io/FileUtil.java index 1c08a045a..a90f205c4 100644 --- a/hutool-core/src/main/java/cn/hutool/core/io/FileUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/io/FileUtil.java @@ -712,12 +712,8 @@ public class FileUtil extends PathUtil { try { Files.delete(file.toPath()); } catch (AccessDeniedException access) { - // 可能遇到只读文件,无法删除,先尝试处理权限 - try { - file.setWritable(true); - } catch (Exception exception) { - throw new IORuntimeException(access); - } + // 可能遇到只读文件,无法删除.使用 file 方法删除 + return file.delete(); } catch (IOException e) { throw new IORuntimeException(e); }