fix file bug

This commit is contained in:
Looly
2022-03-14 23:30:28 +08:00
parent b1e4943e1b
commit e5c253042d
4 changed files with 7 additions and 3 deletions

View File

@@ -700,7 +700,7 @@ public class FileUtil extends PathUtil {
if (null == file) {
return null;
}
return mkdir(file.getParentFile());
return mkdir(getParent(file, 1));
}
/**

View File

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

View File

@@ -1,5 +1,6 @@
package cn.hutool.core.io;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
@@ -48,8 +49,11 @@ public class FileCopierTest {
@Test
@Ignore
public void copyFileByRelativePath(){
// https://github.com/dromara/hutool/pull/2188
// 当复制的目标文件位置是相对路径的时候可以通过
FileCopier copier = FileCopier.create(new File("pom.xml"),new File("aaa.txt"));
copier.copy();
final boolean delete = new File("aaa.txt").delete();
Assert.assertTrue(delete);
}
}