我的程序使用文件数据库,我想知道如何移动文件夹而不删除文件夹内的文件。我正在使用java。当我按下按钮时,我希望它们移动到指定位置。按钮上的代码如下所示:
private void uploadButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
ProjectInfo.documentTitle = fileName.getText();
ProjectInfo.moveFileLocation = fileSpecificLocation.getText();
String name = userNameText.getText();
Signup.fileToMoveTo = "C:\\CloudAurora\\" + name + "\\";
String docTtl = ProjectInfo.documentTitle;
// docTtl.renameTo(new File(Signup.fileToMoveTo));
ProjectInfo.documentTitle = fileName.getText();
ProjectInfo.moveFileLocation = fileSpecificLocation.getText();
String name = userNameText.getText();
Signup.fileToMoveTo = "C:\\CloudAurora\\" + name + "\\";
String docTtl = ProjectInfo.documentTitle;
System.out.println(ProjectInfo.documentTitle);
System.out.println(Signup.fileToMoveTo);
}
如果有人能提供帮助那就太好了。我一直在寻找一种方法来做到这一点,但不知道如何实现
最佳答案
我希望根据您的情况,我正确地提到了源文件和目标文件。下面的代码应该将文件夹与文件一起移动。
File srcFile = new File(docTtl);
File destFile = new File(Signup.fileToMoveTo);
/* Handle IOException for the below line */
Files.move(Paths.get(srcFile.getPath()), Paths.get(destFile.getPath()), StandardCopyOption.REPLACE_EXISTING);
关于java - 如何移动文件夹和文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46165791/