如何使用 FileChooser 保存现有文件

How to save a existing file using FileChooser

我用 JavaFX 开发了一个应用程序。我已经从 TableView 中选择文件并想使用 FileChooser 将其保存在另一个目录中,我该怎么做?

public static void clickDownloadButton(String filename,Stage window){
   File file = new File(filename);
   FileChooser fileChooser = new FileChooser();
   fileChooser.setTitle("Save file");
   fileChooser.showSaveDialog(window);
}

使用java.nio.file.Files -

File dest = fileChooser.showSaveDialog(window);
if (dest != null) {
    try {
        Files.copy(file.toPath(), dest.toPath());
    } catch (IOException ex) {
        // handle exception...
    }
}