change size logic

This commit is contained in:
Looly
2020-04-23 11:08:44 +08:00
parent bd4bd2d4c9
commit 3f97a1e495
2 changed files with 5 additions and 5 deletions

View File

@@ -589,13 +589,12 @@ public class FileUtil {
* 当给定对象为文件时,直接调用 {@link File#length()}<br>
* 当给定对象为目录时,遍历目录下的所有文件和目录,递归计算其大小,求和返回
*
* @param file 目录或文件
* @param file 目录或文件,null或者文件不存在返回0
* @return 总大小bytes长度
*/
public static long size(File file) {
Assert.notNull(file, "file argument is null !");
if (false == file.exists()) {
throw new IllegalArgumentException(StrUtil.format("File [{}] not exist !", file.getAbsolutePath()));
if (null == file || false == file.exists()) {
return 0;
}
if (file.isDirectory()) {