public class hh 
{
       //创建文件对象
      File dir = new File("D:\java");
       //创建文件尖型过滤器
       Filter filter=new Filter("Java");
       //取得文件名的字付串数组 
       String fileList[]=dir.list(filter);
       for (int I=0;I<fileList.length ;I++ )
       {
           //茯取文件对象
           File temFile=new File(fileList[I]);
           //取得文件的属性
           if(temFile.isfile)
               System.out.println("文件"+temFile);
           else
               System.out.println("目录"+temFile);
       }
}
这个类有点问题,
在类里面可以直接就for吗?

解决方案 »

  1.   

    我想你可能
    copy的时候你搞错了一点点
    是什么书啊?那个for应该是在某个方法里面的
      

  2.   

    for循环必须在一个方法里面
    这样就可以了
    而且你的 isFile是不对的,应为 isFile()就我个人来说,我比较喜欢 用String[]来定义字符串组public static void main(String[] args) {
           //创建文件对象
          File dir = new File("D:\\java");
           //创建文件尖型过滤器
           Filter filter=new Filter("Java");
           //取得文件名的字付串数组
          String[] fileList=dir.list(filter);
          for(int I=0;I<5;I++)
           {
               //茯取文件对象
               File temFile=new File(fileList[I]);
               //取得文件的属性
               if(temFile.isFile())
                   System.out.println("文件"+temFile);
               else
                   System.out.println("目录"+temFile);
           }
        }
      }
      

  3.   

    兄弟还是两个地方错呀
    hh.java:10: illegal start of type
               for (int I=0;I<5 ;I++ )
               ^
    hh.java:19: <identifier> expected
               }
                ^
    2 errors
      

  4.   

    搞定是搞定了呀,但执行是这个是什么意思呀?呵呵,
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
            at hh.main(hh.java:14)
      

  5.   

    呵呵,你不会没改我的循环判断吧,I<5,那只是一个测试而已
    把他改回你原来的I<fileList.length
      

  6.   

    数组越界
    你把5改成原来的
    fileList.length 
    试试看吧
      

  7.   

    不过在我机器上判断有问题
    对于文件,isFile()返回false
      

  8.   

    to dynku:
    是不是有些文件的特殊属性就会返回False?我的英文不好,你能不能翻译一下?
    isFilepublic boolean isFile()
    Tests whether the file denoted by this abstract pathname is a normal file. A file is normal if it is not a directory and, in addition, satisfies other system-dependent criteria. Any non-directory file created by a Java application is guaranteed to be a normal file.Returns:true 
    if and only if the file denoted by this abstract pathname exists and is a normal file; 
    false 
    otherwise
      

  9.   

    public boolean isFile()测试 通过相对路径名表示的文件是否是标准的文件。是否是正常文件,取决于它不是一个目录,或者,其他系统规定的标准。任意的由java程序创建的非目录 文件一定是一个标准文件。返回
    true 
    必须是相对路径名存在并且是一个标准的文件
    false 
      

  10.   

    javac: invalid argument: hh
    Usage: javac <options> <source files>
    where possible options include:
      -g                        Generate all debugging info
      -g:none                   Generate no debugging info
      -g:{lines,vars,source}    Generate only some debugging info
      -O                        Optimize; may hinder debugging or enlarge class file  -nowarn                   Generate no warnings
      -verbose                  Output messages about what the compiler is doing
      -deprecation              Output source locations where deprecated APIs are us
    ed
      -classpath <path>         Specify where to find user class files
      -sourcepath <path>        Specify where to find input source files
      -bootclasspath <path>     Override location of bootstrap class files
      -extdirs <dirs>           Override location of installed extensions
      -d <directory>            Specify where to place generated class files
      -encoding <encoding>      Specify character encoding used by source files
      -target <release>         Generate class files for specific VM version
    这是我得出的结果,为什么呀
      

  11.   

    你的命令行写错了如果classpath对的话
    应该用
    javac hh.java
      

  12.   

    javac hh.java
    java hh
    这样哪里有错呀
      

  13.   

    补充
    我说的那种结果说的是
    dynku的结果
    lzlspd的结果好像是因为
    用错了javac吧?
      

  14.   

    好像是程序的问题
    应该是在File的定义上