4

Is it possible to use the JavaFX File Chooser (or a similar alternative) to create new files?

Entering the name of a non-existent file works on Linux (Ubuntu to be exact) but on Windows the file chooser does not allow that.

Nicholas K
  • 15,148
  • 7
  • 31
  • 57
Lehks
  • 2,582
  • 4
  • 19
  • 50

1 Answers1

6

Yes that should be possible, you just need to know the right function to call. The API for FileChooser details them in its opening paragraph here.

A FileChooser can be used to invoke file open dialogs for selecting single file (showOpenDialog), file open dialogs for selecting multiple files (showOpenMultipleDialog) and file save dialogs (showSaveDialog).

USAGE

Save file:

    FileChooser fileChooser = new FileChooser();
    File selectedFile = fileChooser.showSaveDialog(null);

Open one file:

    FileChooser fileChooser = new FileChooser();
    File selectedFile = fileChooser.showOpenDialog(null);

Open multiple files:

    FileChooser fileChooser = new FileChooser();
    List<File> files = fileChooser.showOpenMultipleDialog(null); 
Sami Farhat
  • 1,164
  • 8
  • 12