mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
FileUtil.copy,当来源为文件时,返回文件而非目录
This commit is contained in:
parent
2142d6522a
commit
2bafc6c8a8
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
### 🐣新特性
|
### 🐣新特性
|
||||||
* 【http 】 HttpResponse增加getFileNameFromDisposition方法(pr#2676@Github)
|
* 【http 】 HttpResponse增加getFileNameFromDisposition方法(pr#2676@Github)
|
||||||
|
* 【core 】 FileUtil.copy,当来源为文件时,返回文件而非目录
|
||||||
|
|
||||||
### 🐞Bug修复
|
### 🐞Bug修复
|
||||||
* 【db 】 修复分页时order by截断问题(issue#I5X6FM@Gitee)
|
* 【db 】 修复分页时order by截断问题(issue#I5X6FM@Gitee)
|
||||||
|
@ -168,7 +168,7 @@ public class FileCopier extends SrcToDestCopier<File, FileCopier>{
|
|||||||
@Override
|
@Override
|
||||||
public File copy() throws IORuntimeException{
|
public File copy() throws IORuntimeException{
|
||||||
final File src = this.src;
|
final File src = this.src;
|
||||||
final File dest = this.dest;
|
File dest = this.dest;
|
||||||
// check
|
// check
|
||||||
Assert.notNull(src, "Source File is null !");
|
Assert.notNull(src, "Source File is null !");
|
||||||
if (false == src.exists()) {
|
if (false == src.exists()) {
|
||||||
@ -191,7 +191,7 @@ public class FileCopier extends SrcToDestCopier<File, FileCopier>{
|
|||||||
final File subTarget = isCopyContentIfDir ? dest : FileUtil.mkdir(FileUtil.file(dest, src.getName()));
|
final File subTarget = isCopyContentIfDir ? dest : FileUtil.mkdir(FileUtil.file(dest, src.getName()));
|
||||||
internalCopyDirContent(src, subTarget);
|
internalCopyDirContent(src, subTarget);
|
||||||
} else {// 复制文件
|
} else {// 复制文件
|
||||||
internalCopyFile(src, dest);
|
dest = internalCopyFile(src, dest);
|
||||||
}
|
}
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
@ -244,14 +244,15 @@ public class FileCopier extends SrcToDestCopier<File, FileCopier>{
|
|||||||
* 2、如果目标是一个已存在的目录,则文件拷贝到此目录下,文件名与原文件名一致
|
* 2、如果目标是一个已存在的目录,则文件拷贝到此目录下,文件名与原文件名一致
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @param src 源文件,必须为文件
|
* @param src 源文件,必须为文件
|
||||||
* @param dest 目标文件,如果非覆盖模式必须为目录
|
* @param dest 目标文件,如果非覆盖模式必须为目录
|
||||||
|
* @return 目标的目录或文件
|
||||||
* @throws IORuntimeException IO异常
|
* @throws IORuntimeException IO异常
|
||||||
*/
|
*/
|
||||||
private void internalCopyFile(File src, File dest) throws IORuntimeException {
|
private File internalCopyFile(File src, File dest) throws IORuntimeException {
|
||||||
if (null != copyFilter && false == copyFilter.accept(src)) {
|
if (null != copyFilter && false == copyFilter.accept(src)) {
|
||||||
//被过滤的文件跳过
|
//被过滤的文件跳过
|
||||||
return;
|
return src;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果已经存在目标文件,切为不覆盖模式,跳过之
|
// 如果已经存在目标文件,切为不覆盖模式,跳过之
|
||||||
@ -263,7 +264,7 @@ public class FileCopier extends SrcToDestCopier<File, FileCopier>{
|
|||||||
|
|
||||||
if(dest.exists() && false == isOverride) {
|
if(dest.exists() && false == isOverride) {
|
||||||
//非覆盖模式跳过
|
//非覆盖模式跳过
|
||||||
return;
|
return src;
|
||||||
}
|
}
|
||||||
}else {
|
}else {
|
||||||
//路径不存在则创建父目录
|
//路径不存在则创建父目录
|
||||||
@ -283,6 +284,8 @@ public class FileCopier extends SrcToDestCopier<File, FileCopier>{
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new IORuntimeException(e);
|
throw new IORuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return dest;
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------------------- Private method end
|
//----------------------------------------------------------------------------------------- Private method end
|
||||||
}
|
}
|
||||||
|
@ -502,4 +502,12 @@ public class FileUtilTest {
|
|||||||
path = "test\\aaa.txt";
|
path = "test\\aaa.txt";
|
||||||
Assert.assertFalse(FileUtil.isAbsolutePath(path));
|
Assert.assertFalse(FileUtil.isAbsolutePath(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Ignore
|
||||||
|
public void copyTest2(){
|
||||||
|
final File copy = FileUtil.copy("d:/test/qrcodeCustom.png", "d:/test/pic", false);
|
||||||
|
// 当复制文件到目标目录的时候,返回复制的目标文件,而非目录
|
||||||
|
Console.log(copy);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user