'How get specific file from directory using apache camel in java?

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



Solution 1:[1]

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">

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TacheDeChoco