首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >需要使用java文件读取概念找出具有今天修改日期的特定文件

问需要使用java文件读取概念找出具有今天修改日期的特定文件
EN

Stack Overflow用户
提问于 2016-02-19 19:55:58
回答 1查看 29关注 0票数 0

单个文件夹中有多个文件。如何仅获取特定文件(带有修改日期和时间的文件名),该文件仅在当天被修改?

EN

回答 1

Stack Overflow用户

发布于 2016-02-19 20:09:03

代码语言:javascript
复制
public static void main(String[] args) {
    long now = new Date().getTime();
    long todayMidnightTS = midnightTimeStamp(now);
    //Mind the path used to list children... And also, you may want to retain only child files if that's required.
    List<File> filesModifiedToday = Arrays.asList(new File(".").list()).stream().map(fileName -> new File(fileName)).filter(file -> todayMidnightTS == midnightTimeStamp(file.getCanonicalFile().lastModified())).collect(Collectors.toList());
}
//Returns the timestamp at midnight of the given date time stamp.
//If you use commons-lang, you could call DateUtils.trunc
static long midnightTimeStamp(long dateTS) {
    return dateTS - (dateTS % (24 * 60 * 60000));
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35504729

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档