I'm reading a comma delimited file which has two fields. The file may not contain the second field at times so Spring DelimitedLineTokenizer should not complain when this happens. By stating the following
<property name="lineTokenizer">
<bean
class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
<property name="names"
value="planNumber, paymentAmount">
</property>
<property name="delimiter">
<value>,</value>
</property>
</bean>
</property>
Spring does complain
Caused by: org.springframework.batch.item.file.transform.IncorrectTokenCountException: Incorrect number of tokens found in record: expected 2 actual 1
at org.springframework.batch.item.file.transform.AbstractLineTokenizer.tokenize(AbstractLineTokenizer.java:123)
at org.springframework.batch.item.file.mapping.DefaultLineMapper.mapLine(DefaultLineMapper.java:46)
... 60 more
StringTokenizer would not complain though
By default, the FileItemReader will return null signaling that the step is complete when it encounters an empty file (assuming that the file exists. If it doesn't, we're talking about a ... 4.
Issue#FlatFileItemReader automatically Trimming the leading and trailing spaces forum.springsource.org Hi, FlatFileItemReader trims the leading and trailing spaces automaticaly. How to restrict it.
If the file size is greater than zero, the script reads lines from the file until there are no more lines, or until the number of lines exceeds the expected number of non-data rows. If the number of lines in the file is less than or equal to the expected number of non-data rows, then the file is considered empty.
The Flat File source does not determine whether a flat file contains rows of data before attempting to process it. You may want to improve the efficiency of a package, especially of a package that iterates over numerous flat files, by skipping files that do not contain any rows of data.
set the following property on linetokenizer to false.. this should help avoid the exception getting thrown
<property name="strict" value="false"></property>
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