Java 如何移动文件夹和文件?

Java 如何移动文件夹和文件?,java,file,directory,system,Java,File,Directory,System,我的程序使用文件数据库,我想知道如何在不删除文件夹中的文件的情况下移动文件夹。我正在使用java。当我按下按钮时,我希望它们移动到指定的位置。按钮上的代码如下所示: private void uploadButtonActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: Pr

我的程序使用文件数据库,我想知道如何在不删除文件夹中的文件的情况下移动文件夹。我正在使用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);

我希望根据您的情况,我已经正确地提到了源文件和目标文件。下面的代码应将文件夹与文件一起移动

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);
有关如何执行此操作的详细示例,请参阅代码。有关如何执行此操作的详细示例,请参阅代码。