gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 10:22:18 25 4
gpt4 key购买 nike

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

最佳答案

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));
}

关于java - 需要使用java文件读取概念找出具有今天修改日期的特定文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35504729/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com