JavaFX FileChooser new file

Lehks :

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.

Sami Farhat :

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); 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=77664&siteId=1