如何使用Java中的Apache Camel从目录中获取特定文件?

发布于 2025-01-28 13:11:44 字数 193 浏览 1 评论 0原文

我有一个方案,一个目录包含各种名为pattern filehmm的文件,例如:

hh = hhus mm =分钟

dir: file1200.txt file1210.txt File1220.txt 其他File1.txt 其他file2.txt

我需要根据hh:mm找到最新文件,在我的情况下,它将是file1220.txt

I have an scenario, a directory contains various file named pattern filehhmm like:

hh=hours
mm=minutes

dir:
file1200.txt
file1210.txt
file1220.txt
otherfile1.txt
otherfile2.txt

I need to find latest file based on hh:mm, in my case it would be file1220.txt

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月静好 2025-02-04 13:11:44

使用自定义比较器(基于时间戳部分)对文件(下降)进行对,并将轮询限制为一个文件。
注意在限制轮询文件的数量之前应用排序(请参阅eagermaxmessagespollpoll

<route>
  <from uri="file:mydir?maxMessagesPerPoll=1&eagerMaxMessagesPerPoll=false"/>
  <sort comparator="#class:com.mycompany.MyCusomComparator">

Sort your files (descending) using a custom comparator (based on the timestamp part), and limit the polling to one single file.
Take care to apply the sorting BEFORE limiting the number of polled files (see eagerMaxMessagesPerPoll)

<route>
  <from uri="file:mydir?maxMessagesPerPoll=1&eagerMaxMessagesPerPoll=false"/>
  <sort comparator="#class:com.mycompany.MyCusomComparator">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文