2013-04-26 48 views
-4

这是我的代码JFileChooser,以选择一个文件,现在我想选择多个文件做JFileChooser,以选择多个文件的Java

JFileChooser chose=new JFileChooser(); 
chose.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 
int r=chose.showOpenDialog(new JFrame()); 
if(r == chose.APPROVE_OPTION){ 
    String filepath= chose.getSelectedFile().getAbsolutePath(); 
} 

如何选择使用的JFileChooser请帮助多个文件的.. 。

+2

有至少两个duplicat这个问题,请在询问之前尝试Googleing! http://stackoverflow.com/questions/11922152/jfilechooser-to-open-multiple-txt-files http://stackoverflow.com/questions/13060371/adding-multiple-files-with-jfilechooser – jazzbassrob 2013-04-26 12:06:51

回答

10

chose.setMultiSelectionEnabled(true)

+0

感谢您的快速回放 – 2013-04-26 12:13:19

4

试试这个:

JFileChooser chooser = new JFileChooser(); 
    chooser.setMultiSelectionEnabled(true); 
    chooser.showOpenDialog(frame); 
    File[] files = chooser.getSelectedFiles(); 
+0

感谢您的快速回放 – 2013-04-26 12:13:45

相关问题