It depends on what you mean by "multiple lines". Different operating systems use different line separators.
In Java,
is always carriage return, and
is line feed. On Unix, just
is enough for a newline, whereas many programs on Windows require
. You can get at the platform default newline use System.getProperty("line.separator")
or use String.format("%n")
as mentioned in other answers.
But really, you need to know whether you're trying to produce OS-specific newlines - for example, if this is text which is going to be transmitted as part of a specific protocol, then you should see what that protocol deems to be a newline. For example, RFC 2822 defines a line separator of
and this should be used even if you're running on Unix. So it's all about context.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…