请教各位高手下面程序有何问题?import java.io.File;
import java.io.FileFilter;public class DDD implements FileFilter {
private String str;
public DDD(String str)
{
this.str = str;
}
public boolean accept(File file) {
if(file.isDirectory())
{
return false;
}
String name = file.getName();
int index = name.lastIndexOf(".");//扩展名前的符号"."
if(index == -1)//没有扩展名则返回false
{
return false;
}
else if(index == name.length()-1)//以点号结尾则返回false
{
return false;
}
else
{
return this.str.equals(name.substring(index + 1));
}
} public static void main(String[] args)
{
File file = new File("D:/demo");
DDD txtFilter = new DDD("txt");
File[]files = file.listFiles(txtFilter);//使用过滤器查找文件
for(int i = 0;i < files.length;i++)//一直说此句有错,不解!
{
System.out.println(files[i].getAbsolutePath());
} }}
import java.io.FileFilter;public class DDD implements FileFilter {
private String str;
public DDD(String str)
{
this.str = str;
}
public boolean accept(File file) {
if(file.isDirectory())
{
return false;
}
String name = file.getName();
int index = name.lastIndexOf(".");//扩展名前的符号"."
if(index == -1)//没有扩展名则返回false
{
return false;
}
else if(index == name.length()-1)//以点号结尾则返回false
{
return false;
}
else
{
return this.str.equals(name.substring(index + 1));
}
} public static void main(String[] args)
{
File file = new File("D:/demo");
DDD txtFilter = new DDD("txt");
File[]files = file.listFiles(txtFilter);//使用过滤器查找文件
for(int i = 0;i < files.length;i++)//一直说此句有错,不解!
{
System.out.println(files[i].getAbsolutePath());
} }}
at file.file.main(file.java:38)
for(int i = 0;i < files.length;i++) {
......
}
}