我正在尝试使用文件对话框打开具有特定扩展名( .fcg 或 .wtg )的文件 有办法做到吗??
最佳答案
如果您可以使用JFileChooser
,则可以使用JFileChooser.addChoosableFileFilter()
按扩展名过滤文件。
JFileChooser fileChooser = new JFileChooser();
fileChooser.addChoosableFileFilter(new FileFilter() {
@Override
public String getDescription() {
return "*.fct, *.wtg";
}
@Override
public boolean accept(File f) {
return f.getName().endsWith(".fcg") ||
f.getName().endsWith(".wtg");
}
});
关于java - 如何在fileDialogue中打开具有特定扩展名的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5923040/