请教读取文件夹下某个文件,文件名会带时间戳,要求读最新的那个文件。

white_Eason 2018-05-04 08:56:12
读取linux下FTP日志文件记录,可是日志会自动带一个时间戳,要求读取最新的那个日志文件。汉语描述是苍白的,上图。

我要读取最新的日志文件,该怎么进行选择。
...全文
1000 4 打赏 收藏 举报
写回复
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
fanfather 2018-05-04
  • 打赏
  • 举报
回复
for java 8: Path dir = Paths.get("./path/somewhere"); // specify your directory Optional<Path> lastFilePath = Files.list(dir) // here we get the stream with full directory listing .filter(f -> !Files.isDirectory(f)) // exclude subdirectories from listing .max(Comparator.comparingLong(f -> f.toFile().lastModified())); // finally get the last file using simple comparator by lastModified field if ( lastFilePath.isPresent() ) // your folder may be empty { // do your code here, lastFilePath contains all you need }
QWERT4745 2018-05-04
  • 打赏
  • 举报
回复
遍历文件夹,获取每个文件名,截取后8位数字比较
  • 打赏
  • 举报
回复
设定规则自定义一个compare比较器,去比较这些文件名,利用集合排序功能排序,取想要的就方便的多
「已注销」 2018-05-04
  • 打赏
  • 举报
回复
可以反序排列然后取第一个文件
相关推荐
发帖
Java

4.9w+

社区成员

Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
帖子事件
创建了帖子
2018-05-04 08:56
社区公告
暂无公告