我想监视一个文件夹中是否有文件,想采取定时扫描文件夹,看看里面有没有文件,有的话提出一个做处理,可能要用到文件列表。
但是对java类库不熟,有哪位提供各实例程序或者方法都行,谢谢

解决方案 »

  1.   

    File f = new File("yourpath");
    f.list();
      

  2.   

    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();
        }
      }
    }