如何使用FileChooser保存现有文件

时间:2016-01-09 17:09:11

标签: javafx filechooser

我在JavaFX中开发了一个appication。 Alreadey我从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);
}

1 个答案:

答案 0 :(得分:2)

使用java.nio.file.Files -

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