0

如何使用 AgeFileFilter 读取特定日期文件?我在属性文件中声明了特定日期。我试着用

FileFilter fileFilter = new AgeFileFilter(cutoffDate, false);  

它给了我更新的文件

FileFilter fileFilter = new AgeFileFilter(cutoffDate, true);  

它给了我更老的相同日期文件

但是他们两个都没有按照我的要求工作然后我也尝试了

FileFilter fileFilter = new AgeFileFilter(long cutoffDate);  

但它给了我具有相同日期文件的旧文件
而我的要求是只读取或显示特定日期文件。
那么这怎么可能呢?任何帮助将不胜感激..提前谢谢你

4

1 回答 1

0

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);
于 2018-09-10T13:13:56.270 回答