Because on some systems (Linux/Unix) a new line is defined as \n
while on others (Windows) it is \r\n
. Depending on the software reading the text, it may chose to adhere to this or be more "forgiving" recognizing either or even \r
individually.
Relevant Wikipedia text (https://en.wikipedia.org/wiki/Newline):
Systems based on ASCII or a compatible character set use either LF
(Line feed, '\n', 0x0A, 10 in decimal) or CR (Carriage return, '\r',
0x0D, 13 in decimal) individually, or CR followed by LF (CR+LF,
'\r\n', 0x0D0A)
This is also why you can retrieve the system-defined line separater from the System
class as you did, instead of, for example, having it be some constant in the String
class.