How do I get a platform-dependent new line character?

前端 未结 9 1508
予麋鹿
予麋鹿 2020-11-22 02:17

How do I get a platform-dependent newline in Java? I can’t use \"\\n\" everywhere.

9条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-22 02:33

    StringBuilder newLine=new StringBuilder();
    newLine.append("abc");
    newline.append(System.getProperty("line.separator"));
    newline.append("def");
    String output=newline.toString();
    

    The above snippet will have two strings separated by a new line irrespective of platforms.

提交回复
热议问题