How can I normalize the EOL character in Java?

bilal picture bilal · Sep 23, 2010 · Viewed 45.7k times · Source

I have a linux server and many clients with many operating systems. The server takes an input file from clients. Linux has end of line char LF, while Mac has end of line char CR, and Windows has end of line char CR+LF

The server needs as end of line char LF. Using java, I want to ensure that the file will always use the linux eol char LF. How can I achieve it?

Answer

eumiro picture eumiro · Sep 23, 2010

Could you try this?

content.replaceAll("\\r\\n?", "\n")