2013-04-26 47 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

相關問題