mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
add method
This commit is contained in:
parent
81c7bb4b46
commit
6a04f20fcf
@ -6,6 +6,8 @@
|
||||
# 5.7.6 (2021-07-19)
|
||||
|
||||
### 🐣新特性
|
||||
* 【core 】 增加FieldsComparator(pr#374@Gitee)
|
||||
* 【core 】 FileUtil.del采用Files.delete实现
|
||||
|
||||
### 🐞Bug修复
|
||||
|
||||
|
@ -12,21 +12,19 @@ import java.util.Comparator;
|
||||
* 参阅feilong-core中的PropertyComparator
|
||||
*
|
||||
* @param <T> 被比较的Bean
|
||||
* @author Looly
|
||||
* @author jiangzeyin
|
||||
*/
|
||||
public abstract class BaseFieldComparator<T> implements Comparator<T>, Serializable {
|
||||
private static final long serialVersionUID = -3482464782340308755L;
|
||||
|
||||
/**
|
||||
* 比较器方法
|
||||
* 比较两个对象的同一个字段值
|
||||
*
|
||||
* @param o1 对象1
|
||||
* @param o2 对象2
|
||||
* @return -1 0 1
|
||||
* @param field 字段
|
||||
* @return 比较结果
|
||||
*/
|
||||
@Override
|
||||
public abstract int compare(T o1, T o2);
|
||||
|
||||
protected int compareItem(T o1, T o2, Field field) {
|
||||
if (o1 == o2) {
|
||||
return 0;
|
||||
|
@ -30,6 +30,15 @@ public class FieldComparator<T> extends BaseFieldComparator<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param field 字段
|
||||
*/
|
||||
public FieldComparator(Field field) {
|
||||
this.field = field;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(T o1, T o2) {
|
||||
return compareItem(o1, o2, this.field);
|
||||
|
@ -40,6 +40,7 @@ import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
@ -686,9 +687,15 @@ public class FileUtil extends PathUtil {
|
||||
* 注意:删除文件夹时不会判断文件夹是否为空,如果不空则递归删除子文件或文件夹<br>
|
||||
* 某个文件删除失败会终止删除操作
|
||||
*
|
||||
* <p>
|
||||
* 从5.7.6开始,删除文件使用{@link Files#delete(Path)}代替 {@link File#delete()}<br>
|
||||
* 因为前者遇到文件被占用等原因时,抛出异常,而非返回false,异常会指明具体的失败原因。
|
||||
* </p>
|
||||
*
|
||||
* @param file 文件对象
|
||||
* @return 成功与否
|
||||
* @throws IORuntimeException IO异常
|
||||
* @see Files#delete(Path)
|
||||
*/
|
||||
public static boolean del(File file) throws IORuntimeException {
|
||||
if (file == null || false == file.exists()) {
|
||||
@ -705,7 +712,13 @@ public class FileUtil extends PathUtil {
|
||||
}
|
||||
|
||||
// 删除文件或清空后的目录
|
||||
return file.delete();
|
||||
try {
|
||||
Files.delete(file.toPath());
|
||||
} catch (IOException e) {
|
||||
throw new IORuntimeException(e);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user