Merge pull request #2188 from gongxuanzhang/v5-master

修复Bug:FileCopier的目标文件是相对路径的时候出现异常
This commit is contained in:
Golden Looly 2022-03-14 23:21:06 +08:00 committed by GitHub
commit 87bea48c18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 6 deletions

View File

@ -268,7 +268,7 @@ public class FileCopier extends SrcToDestCopier<File, FileCopier>{
}else {
//路径不存在则创建父目录
//noinspection ResultOfMethodCallIgnored
dest.getParentFile().mkdirs();
dest.getAbsoluteFile().getParentFile().mkdirs();
}
final ArrayList<CopyOption> optionList = new ArrayList<>(2);

View File

@ -5,6 +5,8 @@ import org.junit.Test;
import cn.hutool.core.io.file.FileCopier;
import java.io.File;
/**
* 文件拷贝单元测试
* @author Looly
@ -42,4 +44,12 @@ public class FileCopierTest {
FileCopier copier = FileCopier.create("d:/GReen_Soft/XshellXftpPortable.zip", "c:/hp/");
copier.copy();
}
@Test
@Ignore
public void copyFileByRelativePath(){
// 当复制的目标文件位置是相对路径的时候可以通过
FileCopier copier = FileCopier.create(new File("pom.xml"),new File("aaa.txt"));
copier.copy();
}
}