AmEén ÁhsAn AmEén ÁhsAn - 4 months ago 18
Apache Configuration Question

need a good filefilter

FileFilter fileFilter = new FileFilter() {
@Override
public boolean accept(File pathname)
{
return !pathname.getPath().endsWith("file.tmp");
}
};


This filefilter returns all the files from directory except the one that ends with file.tmp.the problem is I want to add one more filter that ends with file.temp.And I have tried the code below but it doesn't works

FileFilter fileFilter = new FileFilter() {
@Override
public boolean accept(File pathname)
{
return !( (pathname.getPath().endsWith("file.tmp"))&&(pathname.getPath().endsWith("file.temp")));
}
};


Answers that use apache filefilter are also welcomed

Answer

You made wrong check (accepts all files that don't end with file.tmp and file.temp at the same time), while you need:

FileFilter fileFilter = new FileFilter() {
    @Override
    public boolean accept(File pathname)
    {
        return !pathname.getPath().endsWith("file.tmp") && !pathname.getPath().endsWith("file.temp");
    }
};

or with ||:

FileFilter fileFilter = new FileFilter() {
    @Override
    public boolean accept(File pathname)
    {
        return !(pathname.getPath().endsWith("file.tmp") || !pathname.getPath().endsWith("file.temp"));
    }
};