FileChooser method showSaveDialog( ) does not save file javafx?


How does the showSaveDialog( ) method work? I know it returns the selected file but why does it not save the file?

Below is an extract of code I found online.

buttonSave.setOnAction(new EventHandler<ActionEvent>() {

      public void handle(ActionEvent event) {
          FileChooser fileChooser = new FileChooser();

          //Set extension filter
          FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("TXT files (*.txt)", "*.txt");

          //Show save file dialog
          File file = fileChooser.showSaveDialog(primaryStage);
          System.out.println("file is " + file.getName());


Also how do I set what is actually being saved?

3/16/2013 5:47:41 PM

Accepted Answer

Where from should the file chooser know what to write into your file. You need to open a stream on the returned file (e.g. a FileInputStream) and write the information out yourself.

3/17/2013 8:59:49 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow