Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bug? FileFilter vs. FilenameFilter



Hello everybody,

a part of my application is trying to determine the files that were modified after a given date. For that purpose, I have implemented a custom FilenameFilter (listed below, nothing special about that). When I call

// assume dir is a directory and filter is an instance of my filter
dir.listFiles(filter);

I get a list of _all_ the files in that directory where all the files have the "last modified" of the file that was modified most recently. This happens despite the fact that the Finder shows me only ONE file as having been modified in the given timeframe.

By contrast, if I use the FileFilter interface instead (code below), I get the correct results.

If anybody can confirm this, it might be appropriate to file a bug with Apple...

Thanks,

Ralph

Configuration: Mac OS 10.4.2, Java 1.4.2 Update 1

===== FilenameFilter ========

public class LastModifiedFileFilter implements FilenameFilter{

    private Date _lastModifiedSince;

public boolean accept(File file, String name) {
try {
if (file.lastModified() >= lastModifiedSince().getTime()) {
System.out.println("File last modified: " + new Date (file.lastModified()));
System.out.println("timestamp: " + new Date(lastModifiedSince ().getTime()));
return true;
} else {
return false;
}
} catch (Exception e) {
e.printStackTrace();
return false;
}
}


    public Date lastModifiedSince(){
    return _lastModifiedSince;
    }

    public void setLastModifiedSince(Date newLastModifiedSince){
    _lastModifiedSince = newLastModifiedSince;
    }

}

========= FileFilter =================

public class LastModifiedFileFilter implements FileFilter{

    private Date _lastModifiedSince;

public boolean accept(File file) {
try {
if (file.lastModified() >= lastModifiedSince().getTime()) {
System.out.println("File last modified: " + new Date (file.lastModified()));
System.out.println("timestamp: " + new Date(lastModifiedSince ().getTime()));
return true;
} else {
return false;
}
} catch (Exception e) {
e.printStackTrace();
return false;
}
}


    public Date lastModifiedSince(){
    return _lastModifiedSince;
    }

    public void setLastModifiedSince(Date newLastModifiedSince){
    _lastModifiedSince = newLastModifiedSince;
    }

}

=====================================
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.