问题
I am trying to force my spring batch to write file always with CR-LF[EDIT] as line seperator irrespective of the underlying system.
I was trying to use setLineSeperator of FlatFileItemWriter
<bean id="myFileWriter" class="org.springframework.batch.item.file.FlatFileItemWriter">
<property name="lineSeparator">
<value>\r\n</value>
</property>
</bean>
But it always generates file with "\r\n" as string. I am not sure how to unescape this. I looked at the source code of FlatFileItemWriter, there it is just appending the line seperator. Also they are using System.getProperty("line.seperator") for getting default value.
I am sure I am missing something pretty simple.
Thanks.
回答1:
it does work with
<property name="lineSeparator" value=" " />
To insert a CR into XML, you need to use its character entity , for CRLF you need
got it from this stackoverflow answer
for even more background and proper writing (it's not CL-RF) see newline - Difference between \n and \r
回答2:
If you are using Java config, the following might be what you're looking for:
myFileWriter.setLineSeparator("\r\n");
When using the " " solution to write a .txt file, the result was a one line file with the " " showing up as straight text in the file.
来源:https://stackoverflow.com/questions/29481622/spring-batch-output-force-cr-lf-as-line-seperator