简体   繁体   English

java - 如何在java中使用apache camel从目录中获取特定文件?

[英]How get specific file from directory using apache camel in java?

I have an scenario, a directory contains various file named pattern filehhmm like:我有一个场景,一个目录包含各种名为模式 filehhmm 的文件,例如:

hh=hours mm=minutes hh=小时 mm=分钟

dir: file1200.txt file1210.txt file1220.txt otherfile1.txt otherfile2.txt目录: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我需要找到基于 hh:mm 的最新文件,在我的情况下它将是 file1220.txt

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 )在限制轮询文件的数量之前注意应用排序(参见eagerMaxMessagesPerPoll

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM