FileChooser method showSaveDialog( ) does not save file javafx?


Question

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>() {

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

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

          //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?

1
0
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.

1
3/17/2013 8:59:49 AM

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