简体   繁体   中英

JavaFX FileChooser new file

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM