mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
可能遇到只读文件,无法删除,先尝试处理权限
This commit is contained in:
parent
74b4b68bb0
commit
1f070fc5e4
@ -40,10 +40,7 @@ import java.net.URI;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.*;
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.nio.file.StandardCopyOption;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -714,6 +711,13 @@ public class FileUtil extends PathUtil {
|
|||||||
// 删除文件或清空后的目录
|
// 删除文件或清空后的目录
|
||||||
try {
|
try {
|
||||||
Files.delete(file.toPath());
|
Files.delete(file.toPath());
|
||||||
|
} catch (AccessDeniedException access) {
|
||||||
|
// 可能遇到只读文件,无法删除,先尝试处理权限
|
||||||
|
try {
|
||||||
|
file.setWritable(true);
|
||||||
|
} catch (Exception exception) {
|
||||||
|
throw new IORuntimeException(access);
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new IORuntimeException(e);
|
throw new IORuntimeException(e);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user