Reputation: 8957
I am getting flat file parse exception when i use FlatFileItemReader in my job configuration.
Actually it was working fine, but with recent files its throwing error.
org.springframework.batch.item.file.FlatFileParseException: Parsing error at line: 1 in resource=[URL [file:/prod/users/cdi/crh537/Java_All/input/xaaaaa]], input=[16910203315393417SEVAN Q DANG18711 PARK GROVE LNDALLASTX7528751224609645044438000VANVETTE98@YAHOO.COM586404562MAR CL197311192013042504Closed (zero balance DDA)220PUSA]
The main difference is current file records contains some special characters like @ and ().
The following line throws the error. The delimiter used is ^A (linux)
16^A123^A2323232^ADD^SWAN D REE^A123 MMM STRRET^A^ADALLAS^ATX^A2222^A^A^A^A^A^A^A^A^A^A434343434^A23232^A^[email protected]^A586404562^A^A^AMAR^A ^ACL^A121212^A20130425^A04^AClose^A^A220^A^A^AP^AUSA^A
The following is the reader configuration.
<bean id="masterFileItemReader" class="org.springframework.batch.item.file.FlatFileItemReader" scope="step">
<property name="resource" value="#{stepExecutionContext['fileResource']}" />
<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="delimiter" value="${file.delimiter}"/>
<property name="names" value="filed1,field2,...field39" />
</bean>
</property>
<property name="fieldSetMapper">
<bean class="com.batch.SrcMasterFieldSetMapper" />
</property>
</bean>
</property>
</bean>
Upvotes: 3
Views: 15483
Reputation: 3784
I guess you have hidden characters in your file. You can follow this link instructions to verify if and which characters you have in your file.
This question can help you \001 delimiter issues regarding choosing right value for delimiter. As suggested you can try to pass "\u0001"
instead ^A
.
Update:
The actual error was when printed the entire stack trace org.springframework.batch.item.file.transform.IncorrectTokenCountException: Incorrect number of tokens found in record: expected 39 actual 40
Its because the last field in a record/line followed by delimiter and $ not just $, so there is one extra token.
Upvotes: 2