2

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.

Narain
  • 872
  • 9
  • 11

2 Answers2

3

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

Community
  • 1
  • 1
Michael Pralow
  • 6,560
  • 2
  • 30
  • 46
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.

Benn
  • 21
  • 3