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吗?
{
//创建文件对象
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吗?
copy的时候你搞错了一点点
是什么书啊?那个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);
}
}
}
hh.java:10: illegal start of type
for (int I=0;I<5 ;I++ )
^
hh.java:19: <identifier> expected
}
^
2 errors
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
at hh.main(hh.java:14)
把他改回你原来的I<fileList.length
你把5改成原来的
fileList.length
试试看吧
对于文件,isFile()返回false
是不是有些文件的特殊属性就会返回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
true
必须是相对路径名存在并且是一个标准的文件
false
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
这是我得出的结果,为什么呀
应该用
javac hh.java
java hh
这样哪里有错呀
我说的那种结果说的是
dynku的结果
lzlspd的结果好像是因为
用错了javac吧?
应该是在File的定义上