[英]Java: How to read “Files of type” in JFileChooser
I want to create a new file while file type is choosing by the user on JFileChooser. 我希望创建一个新文件,而用户在JFileChooser上选择文件类型。 How this is possible.
这怎么可能。 I use this code for JFileChooser:
我将此代码用于JFileChooser:
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle("Save data in your file format");
FileFilter type1 = new ExtensionFilter("Access 2007 Database(*.accdb)", ".accdb");
FileFilter type2 = new ExtensionFilter("Access 2002-2003 Database(*.mdb)", ".mdb");
chooser.addChoosableFileFilter(type1);
chooser.addChoosableFileFilter(type2);
int actionDialog = chooser.showSaveDialog(frame);
Now I an able to get the "File Name" when the user select any file by this code: 现在,当用户通过此代码选择任何文件时,我能够获得“文件名”:
chooser.getSelectedFile().getName();
But I dont know how to get "Files of type" when user select any file. 但是当用户选择任何文件时,我不知道如何获得“文件类型”。 For the convenience I also attach photo of JFileChooser:
为方便起见,我还附上了JFileChooser的照片:
You can get that information using JFileChooser .getFileFilter()
您可以使用
JFileChooser .getFileFilter()
获取该信息JFileChooser .getFileFilter()
From the Javadocs : 来自Javadocs :
Returns the currently selected file filter
返回当前选定的文件筛选器
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.