我正在编写一个程序来从JFileChooser
中选择文件。我怎样才能得到文件类型(例如是,文件是“.TXT”或“的.html”的“.DAT”等。)
我有下面的代码。我应该增加额外的行数?获取JFileChooser所选文件的类型
JFileChooser choice = new JFileChooser();
int option = choice.showOpenDialog(this);
if (option == JFileChooser.APPROVE_OPTION)
{
String path=choice.getSelectedFile().getAbsolutePath();
String filename=choice.getSelectedFile().getName();
System.out.println(path);
listModel.addElement(path);
System.out.println(filename);
}
如果你只是想扩展名:既然你有文件名,只需选择所有的c包含文件名字符串中最后一个点的字符。 – RaptorDotCpp