How can I normalize the EOL character in Java?

后端 未结 8 851
醉话见心
醉话见心 2020-12-29 03:13

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 cha

相关标签:
8条回答
  • 2020-12-29 03:39

    Use

    System.getProperty("line.separator")
    

    That will give you the (local) EOL character(s). You can then use an analysis of the incomifile to determine what 'flavour' it is and convert accordingly.

    Alternatively, get your clients to standardise!

    0 讨论(0)
  • 2020-12-29 03:42

    Could you try this?

    content.replaceAll("\\r\\n?", "\n")
    
    0 讨论(0)
提交回复
热议问题