How can I normalize the EOL character in Java?

后端 未结 8 945
醉话见心
醉话见心 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:21

    public static String normalize(String val) {
        return val.replace("\r\n", "\n")
                .replace("\r", "\n");
    }
    

    For HTML:

    public static String normalize(String val) {
        return val.replace("\r\n", "
    ") .replace("\n", "
    ") .replace("\r", "
    "); }

提交回复
热议问题