mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
Merge pull request #2188 from gongxuanzhang/v5-master
修复Bug:FileCopier的目标文件是相对路径的时候出现异常
This commit is contained in:
commit
87bea48c18
@ -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);
|
||||
|
@ -5,41 +5,51 @@ import org.junit.Test;
|
||||
|
||||
import cn.hutool.core.io.file.FileCopier;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* 文件拷贝单元测试
|
||||
* @author Looly
|
||||
*
|
||||
*/
|
||||
public class FileCopierTest {
|
||||
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void dirCopyTest() {
|
||||
FileCopier copier = FileCopier.create("D:\\Java", "e:/eclipse/eclipse2.zip");
|
||||
copier.copy();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void dirCopyTest2() {
|
||||
//测试带.的文件夹复制
|
||||
FileCopier copier = FileCopier.create("D:\\workspace\\java\\.metadata", "D:\\workspace\\java\\.metadata\\temp");
|
||||
copier.copy();
|
||||
|
||||
|
||||
FileUtil.copy("D:\\workspace\\java\\looly\\hutool\\.git", "D:\\workspace\\java\\temp", true);
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = IORuntimeException.class)
|
||||
public void dirCopySubTest() {
|
||||
//测试父目录复制到子目录报错
|
||||
FileCopier copier = FileCopier.create("D:\\workspace\\java\\.metadata", "D:\\workspace\\java\\.metadata\\temp");
|
||||
copier.copy();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void copyFileToDirTest() {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user