user1919581
user1919581

Reputation: 511

Spring Batch - Write multiple files based on records count

In spring batch, I have an requirement to read from the database and to write in a file, The no of rows allowed in a file is N, so if N+10 records are fetched then two files should be created containing N rows and 10 rows respectively.

Can someone please help me with the writer implementation? Is there any other easy way of doing it? Thanks.

Upvotes: 1

Views: 2968

Answers (1)

Karthik Prasad
Karthik Prasad

Reputation: 10004

Spring batch has MultiResourceItemWriter were you can write based on number of lines

<bean id="multiWriter"
        class="org.springframework.batch.item.file.MultiResourceItemWriter">
        <property name="delegate" ref="flatFileItemWriter" />
        <property name="itemCountLimitPerResource" value="3" />
        <property name="resource" value="file:c:/logs/te" />
</bean>

Upvotes: 1

Related Questions