mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
remove FileCopier
This commit is contained in:
@@ -1,59 +0,0 @@
|
||||
package cn.hutool.core.io;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
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() {
|
||||
final FileCopier copier = FileCopier.of("D:\\Java", "e:/eclipse/eclipse2.zip");
|
||||
copier.copy();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void dirCopyTest2() {
|
||||
//测试带.的文件夹复制
|
||||
final FileCopier copier = FileCopier.of("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() {
|
||||
//测试父目录复制到子目录报错
|
||||
final FileCopier copier = FileCopier.of("D:\\workspace\\java\\.metadata", "D:\\workspace\\java\\.metadata\\temp");
|
||||
copier.copy();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void copyFileToDirTest() {
|
||||
final FileCopier copier = FileCopier.of("d:/GReen_Soft/XshellXftpPortable.zip", "c:/hp/");
|
||||
copier.copy();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void copyFileByRelativePath(){
|
||||
// https://github.com/dromara/hutool/pull/2188
|
||||
// 当复制的目标文件位置是相对路径的时候可以通过
|
||||
final FileCopier copier = FileCopier.of(new File("pom.xml"),new File("aaa.txt"));
|
||||
copier.copy();
|
||||
final boolean delete = new File("aaa.txt").delete();
|
||||
Assert.assertTrue(delete);
|
||||
}
|
||||
}
|
@@ -92,15 +92,6 @@ public class FileUtilTest {
|
||||
Assert.assertEquals(srcFile.length(), destFile.length());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void copyFilesFromDirTest() {
|
||||
final File srcFile = FileUtil.file("D:\\驱动");
|
||||
final File destFile = FileUtil.file("d:\\驱动备份");
|
||||
|
||||
FileUtil.copyFilesFromDir(srcFile, destFile, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void copyDirTest() {
|
||||
|
79
hutool-core/src/test/java/cn/hutool/core/io/file/PathCopyTest.java
Executable file
79
hutool-core/src/test/java/cn/hutool/core/io/file/PathCopyTest.java
Executable file
@@ -0,0 +1,79 @@
|
||||
package cn.hutool.core.io.file;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
/**
|
||||
* 文件或目录拷贝测试
|
||||
*/
|
||||
public class PathCopyTest {
|
||||
|
||||
@Test
|
||||
public void copySameFileTest() {
|
||||
final Path path = Paths.get("d:/test/dir1/test1.txt");
|
||||
//src路径和target路径相同时,不执行操作
|
||||
PathUtil.copy(
|
||||
path,
|
||||
path);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void copySameDirTest() {
|
||||
final Path path = Paths.get("d:/test/dir1");
|
||||
//src路径和target路径相同时,不执行操作
|
||||
PathUtil.copyContent(
|
||||
path,
|
||||
path);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void copyFileToDirTest() {
|
||||
// src为文件,target为已存在目录,则拷贝到目录下,文件名不变。
|
||||
PathUtil.copy(
|
||||
Paths.get("d:/test/dir1/test1.txt"),
|
||||
Paths.get("d:/test/dir2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void copyFileToPathNotExistTest() {
|
||||
// src为文件,target为不存在路径,则目标以文件对待(自动创建父级目录)
|
||||
// 相当于拷贝后重命名
|
||||
PathUtil.copy(
|
||||
Paths.get("d:/test/dir1/test1.txt"),
|
||||
Paths.get("d:/test/test2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void copyFileToFileTest() {
|
||||
//src为文件,target是一个已存在的文件,则当{@link CopyOption}设为覆盖时会被覆盖,默认不覆盖。
|
||||
PathUtil.copy(
|
||||
Paths.get("d:/test/dir1/test1.txt"),
|
||||
Paths.get("d:/test/test2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void copyDirToDirTest() {
|
||||
//src为目录,target为已存在目录,整个src目录连同其目录拷贝到目标目录中
|
||||
PathUtil.copy(
|
||||
Paths.get("d:/test/dir1/"),
|
||||
Paths.get("d:/test/dir2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void copyDirToPathNotExistTest() {
|
||||
//src为目录,target为不存在路径,则自动创建目标为新目录,整个src目录连同其目录拷贝到目标目录中
|
||||
PathUtil.copy(
|
||||
Paths.get("d:/test/dir1/"),
|
||||
Paths.get("d:/test/dir3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void copyDirToFileTest() {
|
||||
//src为目录,target为文件,抛出IllegalArgumentException
|
||||
PathUtil.copy(
|
||||
Paths.get("d:/test/dir1/"),
|
||||
Paths.get("d:/test/exist.txt"));
|
||||
}
|
||||
}
|
@@ -13,7 +13,7 @@ public class PathUtilTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void copyFileTest(){
|
||||
PathUtil.copyFile(
|
||||
PathUtil.copy(
|
||||
Paths.get("d:/test/1595232240113.jpg"),
|
||||
Paths.get("d:/test/1595232240113_copy.jpg"),
|
||||
StandardCopyOption.COPY_ATTRIBUTES,
|
||||
|
Reference in New Issue
Block a user