如何在 JavaFX 中使用 FileChooser 保存文件

GVA*_*Art 1 javafx filechooser

如何使用 JavaFX 中的 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);
}
Run Code Online (Sandbox Code Playgroud)

Ita*_*tai 5

使用java.nio.file.Files-

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