Kun*_*dan 2 java swing jfilechooser
我正在编写一个程序来从中选择文件JFileChooser.如何获取文件类型(例如,该文件是" .dxt "或" .dtml "的" .dat "等.)
我有以下代码.我应该怎么添加额外的线?
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);
}
Run Code Online (Sandbox Code Playgroud)
小智 7
使用String #substring和String#lastIndexOf:
filename.substring(filename.lastIndexOf("."),filename.length())
| 归档时间: |
|
| 查看次数: |
6000 次 |
| 最近记录: |