membersound membersound - 6 months ago 60
Java Question

How to read all files in a folder with spring-batch and MultiResourceItemReader?

I want to configure

to read all
files inside a specific folder sequentially.

The following does not work because the delegate will try to open a file named
, which of course is invalid. What do I have to change here?

public ItemReader<String> reader() {
MultiResourceItemReader<String> reader = new MultiResourceItemReader<>();
reader.setResources(new Resource[] {new FileSystemResource("/myfolder/*.csv")});
reader.setDelegate(new FlatFileItemReader<>(..));
return reader;

The equivalent xml configuration would be written as follows, how could I rewrite it to java only config?

<bean id="reader" class="org.springframework.batch.item.file.MultiResourceItemReader">
<property name="resources" value="/mypfolder/*.csv"/>
<property name="delegate" ref="flatFileItemReader"/>

Answer Source

I think you should use a PathMatchingResourcePatternResolver.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download