Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
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^AABC@ABC.COM^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">
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>
–
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.
–
–
–
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.