mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix code
This commit is contained in:
parent
6a3639a78e
commit
d52c32154a
@ -709,8 +709,12 @@ public class FileUtil extends PathUtil {
|
||||
}
|
||||
|
||||
// 删除文件或清空后的目录
|
||||
final Path path = file.toPath();
|
||||
try {
|
||||
delFile(file.toPath());
|
||||
delFile(path);
|
||||
} catch (DirectoryNotEmptyException e){
|
||||
// 遍历清空目录没有成功,此时补充删除一次(可能存在部分软链)
|
||||
del(path);
|
||||
} catch (IOException e) {
|
||||
throw new IORuntimeException(e);
|
||||
}
|
||||
@ -749,10 +753,8 @@ public class FileUtil extends PathUtil {
|
||||
|
||||
final File[] files = directory.listFiles();
|
||||
if (null != files) {
|
||||
boolean isOk;
|
||||
for (File childFile : files) {
|
||||
isOk = del(childFile);
|
||||
if (isOk == false) {
|
||||
if(false == del(childFile)){
|
||||
// 删除一个出错则本次删除任务失败
|
||||
return false;
|
||||
}
|
||||
|
@ -644,7 +644,7 @@ public class PathUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件,不追踪软链
|
||||
* 删除文件或空目录,不追踪软链
|
||||
*
|
||||
* @param path 文件对象
|
||||
* @throws IOException IO异常
|
||||
|
@ -23,6 +23,15 @@ public class DelVisitor extends SimpleFileVisitor<Path> {
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 访问目录结束后删除目录,当执行此方法时,子文件或目录都已访问(删除)完毕<br>
|
||||
* 理论上当执行到此方法时,目录下已经被清空了
|
||||
*
|
||||
* @param dir 目录
|
||||
* @param e 异常
|
||||
* @return {@link FileVisitResult}
|
||||
* @throws IOException IO异常
|
||||
*/
|
||||
@Override
|
||||
public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException {
|
||||
if (e == null) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user