【Swing】如何打开文件选择对话框,选择文件
请参考以下代码:
JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter( "Sql & Txt files", "sql", "txt"); chooser.setFileFilter(filter); int returnVal = chooser.showOpenDialog(chooser); if(returnVal == JFileChooser.APPROVE_OPTION) { String filePathname=chooser.getSelectedFile().getPath(); System.out.println(filePathname); }
效果如下图:
END