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

前端 未结 9 1300
予麋鹿
予麋鹿 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:45

    The commons-lang library has a constant field available called SystemUtils.LINE_SEPARATOR

    0 讨论(0)
  • 2020-11-22 02:56

    This is also possible: String.format("%n").

    Or String.format("%n").intern() to save some bytes.

    0 讨论(0)
  • 2020-11-22 02:57

    You can use

    System.getProperty("line.separator");
    

    to get the line separator

    0 讨论(0)
提交回复
热议问题