[英]Read file content which start with # using Spring Batch
I have a very simple Spring Batch application which reads multiple file and write it to one file. 我有一个非常简单的Spring Batch应用程序,可以读取多个文件并将其写入一个文件。 My project is working super fine in all scenario except if a line start with "#" in my file.
我的项目在所有情况下都可以正常工作,除非文件中的行以“#”开头。 My reader doesn't read that line.
我的读者没有读那行。 Problem is that the upper system is going to send down the files where everyline start with # :(
问题是上层系统将向下发送文件,每行以#:(
Does anyone faced similar issue and how to solve it. 是否有人面临类似的问题以及如何解决。
Thanks in advance.. 提前致谢..
My tokenizerconfig 我的tokenizerconfig
<bean id="accountDataTokenizer" class="org.springframework.batch.item.file.transform.PatternMatchingCompositeLineTokenizer">
<property name="tokenizers">
<map>
<entry key="#ACCOUNT*" value-ref="headerRecordTokenizer" />
<entry key="*" value-ref="defaultLineTokenizer" />
</map>
</property>
</bean>
The FlatFileItemReader
provides the ability to set a string that identifies commented out lines. FlatFileItemReader
提供了设置字符串的功能,该字符串用于标识注释掉的行。 This is done via the FlatFileItemReader#setComments(String[] prefixes)
configuration. 这是通过
FlatFileItemReader#setComments(String[] prefixes)
配置完成的。 So in your case, you'd configure your FlatFileItemReader
as follows: 因此,在您的情况下,您可以按以下方式配置
FlatFileItemReader
:
@Bean
public FlatFileItemReader reader() {
FlatFileItemReader reader = new FlatFileItemReader();
...
reader.setComments(new String[] {"#"});
return reader;
}
You can read more about the FlatFileItemReader
and this method in the documentation here: https://docs.spring.io/spring-batch/trunk/apidocs/org/springframework/batch/item/file/FlatFileItemReader.html 您可以在以下文档中阅读有关
FlatFileItemReader
和此方法的更多信息: https : //docs.spring.io/spring-batch/trunk/apidocs/org/springframework/batch/item/file/FlatFileItemReader.html
如果第一行始终为“#”,则可以通过将此属性添加到itemReader(FlatFileItemReader)中来跳过以读取文件的第一行:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.