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

@ -21,6 +21,7 @@
* 【core 】 修复ReflectUtil.getMethods获取接口方法问题issue#I4WUWR@Gitee * 【core 】 修复ReflectUtil.getMethods获取接口方法问题issue#I4WUWR@Gitee
* 【core 】 修复NamingCase中大写转换问题pr#572@Gitee * 【core 】 修复NamingCase中大写转换问题pr#572@Gitee
* 【http 】 修复GET重定向时携带参数问题issue#2189@Github * 【http 】 修复GET重定向时携带参数问题issue#2189@Github
* 【core 】 修复FileUtil、FileCopier相对路径获取父路径错误问题pr#2188@Github
------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------
# 5.7.22 (2022-03-01) # 5.7.22 (2022-03-01)

View File

@ -700,7 +700,7 @@ public class FileUtil extends PathUtil {
if (null == file) { if (null == file) {
return null; 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 { }else {
//路径不存在则创建父目录 //路径不存在则创建父目录
//noinspection ResultOfMethodCallIgnored FileUtil.mkParentDirs(dest);
dest.getAbsoluteFile().getParentFile().mkdirs();
} }
final ArrayList<CopyOption> optionList = new ArrayList<>(2); final ArrayList<CopyOption> optionList = new ArrayList<>(2);

View File

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