Reputation: 29
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?
Upvotes: 0
Views: 6634
Reputation: 5897
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.
Upvotes: 1