Spring batch output force CR-LF as line seperator

倖福魔咒の 提交于 2019-12-24 03:53:28

问题


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="&#13;&#10;" />

To insert a CR into XML, you need to use its character entity &#13;, for CRLF you need &#13;&#10;

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 "&#13;&#10;" solution to write a .txt file, the result was a one line file with the "&#13;&#10;" showing up as straight text in the file.



来源:https://stackoverflow.com/questions/29481622/spring-batch-output-force-cr-lf-as-line-seperator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!