简体   繁体   English

Spring批处理读取多个具有动态名称的文件

[英]Spring Batch Reading Multiple files with Dynamic names

I am a newbie in Spring Batch. 我是Spring Batch的新手。 I have already created working code using FlatFileItemReader where I am getting the preset file name from a property file. 我已经使用FlatFileItemReader创建了工作代码,可以从属性文件中获取预设文件名。 In a new requirement I would not know the file name. 在新要求中,我将不知道文件名。 For instance, the below could be the files and their names, all placed in the same location. 例如,以下可能是文件及其名称,它们都放在同一位置。

...\files2read\<SOME-RANDOM-ID>.<YYMMDD>.<EXTN>

...\files2read\123.140613.ABB - @Pick this
...\files2read\234.140610.ABB
...\files2read\345.140607.ABB

...\files2read\123.140613.ABC - @Pick this
...\files2read\234.140610.ABC
...\files2read\345.140607.ABC

...\files2read\123.140613.ABD - @Pick this
...\files2read\234.140610.ABD
...\files2read\345.140607.ABD

There might be multiple files as the time goes, but I need to pick the latest file looking at the date on the file name, and per each file extension (ie, @Pick this) 随着时间的流逝,可能会有多个文件,但是我需要选择最新的文件,并查看文件名上的日期以及每个文件扩展名(即@Pick this)。

I have looked at the MultiResourceItemReader where the resources can be specified as pattern . 我看过MultiResourceItemReader,其中资源可以指定为pattern This will allow me to read all the files matching a file extension but not as I require here. 这将使我能够读取所有与文件扩展名匹配的文件,但不是我在这里需要的文件。 Is there an elegant solution to this, rather than writing each file type pattern as a separate step? 是否有一个优雅的解决方案,而不是将每个文件类型模式编写为一个单独的步骤? Also I still not sure how to pick the latest file looking at the date here. 此外,我仍然不确定如何在此处查看日期选择最新文件。

I am using this example as a reference. 我使用此示例作为参考。 Please let me know your thoughts. 请让我知道你的想法。 Thanks in advance. 提前致谢。

您可以实现自己的ResourcePatternResolver并返回所需的资源。

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

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