【问题标题】:How to move folder and files?如何移动文件夹和文件?
【发布时间】:2017-09-11 23:41:56
【问题描述】:

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

如果有人可以提供帮助,那就太好了。我一直在寻找一种方法来做到这一点,但无法弄清楚如何

【问题讨论】:

  • 查看代码posted here,了解如何执行此操作的一个不错的示例。

标签: java file directory system


【解决方案1】:

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

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);

【讨论】:

    猜你喜欢
    • 2023-03-18
    • 1970-01-01
    • 2021-09-26
    • 2022-01-19
    • 1970-01-01
    • 1970-01-01
    • 2020-08-30
    • 1970-01-01
    • 2014-02-13
    相关资源
    最近更新 更多