Read Specific Date File using AgeFileFilter

827 Views Asked by At

How to Read specific date file Using AgeFileFilter? I declare particular date in property files. I tried to do that with

FileFilter fileFilter = new AgeFileFilter(cutoffDate, false);  

It gives me Newer files

FileFilter fileFilter = new AgeFileFilter(cutoffDate, true);  

And it gives me older with equal date files

But both of them not working as per my requirement then i also tried

FileFilter fileFilter = new AgeFileFilter(long cutoffDate);  

But it gives me Older files with equal date files
And my requirement is to read or display only particular date file..
So how is it possible? Any help will be appreciate..Thank you in Advance

1

There are 1 best solutions below

2
jbx On

AgeFileFilter only filters files before or after the cut off date-time instance.

Remember that the cutOffDate parameter is the unix date-time in milliseconds Will you know the exact date and time by the millisecond and have it saved in your property file?

If yes (unlikely), why don't you simply write your own FileFilter? It is only a single method, and with Java 8 you can write it easily like this:

long cutOffDate = 1536584743813L;

FileFilter fileFilter = file -> file.lastModified() == cutOffDate;

I suspect that it is unlikely what you want though. Do you load just a date (without time) from your property file?

Then you probably want to get the date of the file from the last modified timestamp.

The following only accepts files that were modified today. Instead of today you can have any LocalDate loaded from your property file.

LocalDate today = LocalDate.now();

FileFilter fileFilter = file -> LocalDate.from(Instant.ofEpochMilli(file.lastModified())).isEqual(today);