繁体   English   中英

如何使用Java将文件夹从一个位置移动到另一位置

[英]How to move folder from one location to another location using java

如何将一个文件夹从一个位置移动到另一位置? 这是我所做的示例代码,但这里显示的是java.nio.file.NoSuchFileException我正在使用此程序包: import java.nio.file.Files; import java.nio.file.StandardCopyOption; import java.nio.file.Files; import java.nio.file.StandardCopyOption;

Path path1 = FileSystems.getDefault().getPath("D:\\VFSImagecomp\\compressed\\");
Path path2 = FileSystems.getDefault().getPath("D:\\destinitionFile\\");

Files.move(path1, path2, StandardCopyOption.REPLACE_EXISTING);

在这里,我正在尝试将压缩文件夹移到destinitionFile Folder。但是,它不起作用。能否建议我?

您需要指定目的地的名称,否则它将替换您的parent文件夹(因为您正在使用REPLACE_EXISTING

 Path path1 = FileSystems.getDefault().getPath("D:\\VFSImagecomp\\compressed");
 Path path2 = FileSystems.getDefault().getPath("D:\\destinitionFile\\myNewDirectory");

如果您要保持相同的名称,请执行以下操作:

 Path path2 = FileSystems.getDefault().getPath("D:\\destinitionFile\\compressed");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM