假设有一目录:E:\pathFile file = new File("e:\\path");
File[] listfile = file.listFiles();
file[i]就是你想要的文件

解决方案 »

  1.   

    public void deleteTree(File path){
      File[] files = path.listFiles();
      
      for(int i=0;i<files.length;i++){
        File child = files[i];
        if (child.isDirectory()){
          deleteTree(child);
        }
        child.deleteFile();
      }
    }
      

  2.   

    import java.io.*;public class DirList3 {
      public static void main(final String[] args) {
        try {
          File path = new File(".");
          String[] list;
          if(args.length == 0)
            list = path.list();
          else 
            list = path.list(
              new FilenameFilter() {
                public boolean 
                accept(File dir, String n) {
                  String f = new File(n).getName();
                  return f.indexOf(args[0]) != -1;
                }
              });
          for(int i = 0; i < list.length; i++)
            System.out.println(list[i]);
        } catch(Exception e) {
          e.printStackTrace();
        }
      }
    }
    参考一下吧,
    --其中有个目录滤除器
    --缺省为.目录稍微改变一下,会符合自己要求的
      

  3.   

    Thank Up,可惜我的这50分早就给出去了,可不可以再给一次?