mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix del bug
This commit is contained in:
parent
e4848d5fe7
commit
69b981e8c0
@ -3,7 +3,7 @@
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
# 5.7.7 (2021-08-01)
|
||||
# 5.7.7 (2021-08-02)
|
||||
|
||||
### 🐣新特性
|
||||
* 【core 】 增加LookupFactory和MethodHandleUtil(issue#I42TVY@Gitee)
|
||||
@ -18,6 +18,7 @@
|
||||
* 【jwt 】 修复JWTUtil中几个方法非static的问题(issue#1735@Github)
|
||||
* 【core 】 修复SpringUtil无法处理autowired问题(pr#388@Gitee)
|
||||
* 【core 】 修复AbsCollValueMap中常量拼写错误(pr#1736@Github)
|
||||
* 【core 】 修复FileUtil.del在文件只读情况下无法删除的问题(pr#389@Gitee)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -710,10 +710,7 @@ public class FileUtil extends PathUtil {
|
||||
|
||||
// 删除文件或清空后的目录
|
||||
try {
|
||||
Files.delete(file.toPath());
|
||||
} catch (AccessDeniedException access) {
|
||||
// 可能遇到只读文件,无法删除.使用 file 方法删除
|
||||
return file.delete();
|
||||
delFile(file.toPath());
|
||||
} catch (IOException e) {
|
||||
throw new IORuntimeException(e);
|
||||
}
|
||||
|
@ -135,12 +135,7 @@ public class PathUtil {
|
||||
if (isDirectory(path)) {
|
||||
Files.walkFileTree(path, DelVisitor.INSTANCE);
|
||||
} else {
|
||||
try {
|
||||
Files.delete(path);
|
||||
} catch (AccessDeniedException access) {
|
||||
// 可能遇到只读文件,无法删除.使用 file 方法删除
|
||||
return path.toFile().delete();
|
||||
}
|
||||
delFile(path);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new IORuntimeException(e);
|
||||
@ -596,4 +591,22 @@ public class PathUtil {
|
||||
public static Path mkParentDirs(Path path) {
|
||||
return mkdir(path.getParent());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件,不追踪软链
|
||||
*
|
||||
* @param path 文件对象
|
||||
* @throws IORuntimeException IO异常
|
||||
* @since 5.7.7
|
||||
*/
|
||||
protected static void delFile(Path path) throws IOException {
|
||||
try {
|
||||
Files.delete(path);
|
||||
}catch (AccessDeniedException e) {
|
||||
// 可能遇到只读文件,无法删除.使用 file 方法删除
|
||||
if(false == path.toFile().delete()) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user