mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
修复FileUtil.copyFile没有创建父目录导致的问题
This commit is contained in:
parent
1be871154f
commit
743ff04dcf
@ -266,6 +266,9 @@ public class PathUtil {
|
|||||||
public static Path copy(final InputStream src, final Path target, final CopyOption... options) throws IORuntimeException {
|
public static Path copy(final InputStream src, final Path target, final CopyOption... options) throws IORuntimeException {
|
||||||
Assert.notNull(target, "Destination File or directory is null !");
|
Assert.notNull(target, "Destination File or directory is null !");
|
||||||
|
|
||||||
|
// 创建级联父目录
|
||||||
|
mkParentDirs(target);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Files.copy(src, target, options);
|
Files.copy(src, target, options);
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
package org.dromara.hutool.core.io.file;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Disabled;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
|
||||||
|
public class Issue3557Test {
|
||||||
|
@Test
|
||||||
|
@Disabled
|
||||||
|
public void copyFileTest() {
|
||||||
|
// 如果只是文件不存在,则不会报错
|
||||||
|
// 如果文件所在目录不存在,则会报错
|
||||||
|
FileUtil.copy(FileUtil.getInputStream("d:/test/aaa.xlsx"), FileUtil.file("d:/test2/aaa_copy.xlsx"), StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Disabled
|
||||||
|
public void copyFileTest2() {
|
||||||
|
FileUtil.copy(FileUtil.file("d:/test/aaa.xlsx"), FileUtil.file("d:/test2/aaa_copy.xlsx"), true);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user