如题.
顺便问一下为什么在一个有文件的目录的对象里用length(),其返回的值
老是等于0啊??
谢谢了!

解决方案 »

  1.   

    import java.io.*;public class Test2 {
      public static void visit(File f)
      {
        System.out.println(f);
      }  public static void walk(File f)
      {
        visit(f);
        if (f.isDirectory()) {
          String list[] = f.list();
          for (int i = 0; i < list.length; i++)
            walk(new File(f, list[i]));
        }
      }  public static void main(String args[])
      {
        File dir = new File("d:/tmp");
        walk(dir);
      }
    }
    自己看看,改下就可以了。
      

  2.   

    实际上,目录的length()方法返回的值是不定的.     * Returns the length of the file denoted by this abstract pathname.
         * The return value is unspecified if this pathname denotes a directory.File file ....;
    if(file != null && file.listFiles() != null && file.listFiles().length != 0) {
      System.out.println("has files or sub directories");
    }