1

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.

3
  • Currently am trying in a separate tasklet by passing the object list and traversing the list and creating files. I want to know how to achieve this through spring writer itself.. Commented May 7, 2015 at 6:24
  • MultiResourceItemWriter Commented May 7, 2015 at 7:08
  • Thanks Luca Basso Ricci.. Commented May 8, 2015 at 4:51

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

1 Comment

For each file? The files generated in the above case would be te.1, te.2 etc. you can pass the file name as argument for spring properties or from SB Jobparameter, <property name="resource" value="file:${filelocation}" />

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.