I am new on spring batch. My task is to develop code which read a flat file where values are separated by pipe "|". I found that I can do it by FlatFileReader. But I am not getting how to set delimiter value during read and how to map each column with my POJO member variables.
Sample values in flat file are following .
3345|742|0|N
3346|743|1|A
3347|742|0|N
3348|742|1|C
3345|743|0|K
Thanks in advance.
The FlatFileItemReader
delegates the parsing of each record to a LineTokenizer
(via the LineMapper
). I'm assuming you're using the DelimitedLineTokenizer
which allows you to set a delimiter (the default is a ,). To configure this with a pipe as the delimiter:
<bean id="reader" class="org.springframework.batch.item.file.FlatFileItemReader">
<property name="resource" value="<SOME_VALUE>"/>
<property name="lineMapper">
<bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
<property name="lineTokenizer">
<bean class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
<property name="names" value="<LIST_OF_VALUES>"/>
<property name="delimiter" value="|"/>
</bean>
</property>
<property name="fieldSetMapper" ref="myFieldSetMapper"/>
</bean>
</property>
</bean>
Where <SOME_VALUE>
is the pattern for your file to be read and <LIST_OF_VALUES>
is the list of column names in your delimited file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With