是否可以使用 JavaFX 文件选择器(或类似的替代方法)来创建新文件?
输入不存在文件的名称在 Linux 上有效(准确地说是 Ubuntu),但在 Windows 上文件选择器不允许这样做。
最佳答案
是的,这应该是可能的,您只需要知道要调用的正确函数即可。 FileChooser
的 API 在其开头段落 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).
用法
保存文件:
FileChooser fileChooser = new FileChooser();
File selectedFile = fileChooser.showSaveDialog(null);
打开一个文件:
FileChooser fileChooser = new FileChooser();
File selectedFile = fileChooser.showOpenDialog(null);
打开多个文件:
FileChooser fileChooser = new FileChooser();
List<File> files = fileChooser.showOpenMultipleDialog(null);
关于JavaFX FileChooser 新文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52464608/