3 回答

TA贡献1891条经验 获得超3个赞
尝试这个:
@Override
public boolean accept(File dir, String name) {
File file = new File(dir, name);
return name.endsWith(x) && file.length() == size;
}

TA贡献1843条经验 获得超7个赞
@Override
public boolean accept(File dir, String name) {
//i can't use the dir.length because it checks the size of the directory and not the inside files
if(name.endsWith(x))
{
File f = new File(dir.getPath(), name);
return f.length() == size;
}
return false;
}

TA贡献1744条经验 获得超4个赞
使用 FileFiler 而不是 FilenameFilter 更适合您打算实现的目标。您的过滤器类将如下所示:
import java.io.File;
import java.io.FileFilter;
public class MyFileFilter implements FileFilter {
private String x;
private int size;
public MyFileFilter(String x, int size){
this.x = x;
this.size = size;
}
@Override
public boolean accept(File file) {
return file.endsWith(x) && file.length() == size;
}
}
添加回答
举报