chooser=new JFileChooser();
         chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
  int n = chooser.showOpenDialog(p1 );
  if(n==JFileChooser.APPROVE_OPTION)  
                  {
    sourceroot=chooser.getSelectedFile().getAbsolutePath();
    opentext.setText(sourceroot);
                  }此处的chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);读取的是当前选择的目录,但是不包括子目录,怎么才能读取子目录中所需的所有文件?如果不是这个方法,那个应该用哪个方法?
谢谢各位了。

解决方案 »

  1.   

    File[] files = yourSelectedFile.listFiles(new FileFilter() {  
          public boolean accept(File pathname) {
            return !pathname.isDirectory();
          }
        });
      

  2.   

    好像还是不能找到,这个FileFilter是java.io.FileFilter还是javax.swing.filechooser.FileFilter?