java - \n and \r seem to work everywhere. Why is line.separator more portable? -


i perusing through questions, , found system.getproperty(line.separator) used in place of \n author's comment code "portable". reading through various forums, i've seen 2 groups:

  1. people there's difference between linux's , windows' interpretation of newline characters, , compensates (with no clear evidence).
  2. people there's no difference showing code , output examples, applies code example , not universally.

my feeling is: it's non-standard os's, example company's industrial scanner's os example, you'll notice difference. when going see difference between \n , line.separator? can show example, please? how did go discovering variation occurs?

incorrect line endings frequent annoyance. example, windows notepad shows when writing file \n instead of \r\n (windows' line.separator):

notepad boxes instead of line breaks

those little boxes supposed line breaks.

the other way around, when \r\n used in place of \n (unix' line.separator), way worse, , breaks shell scripts , config files in weird , wonderful ways.

for example, sh outputs on debian , derived distros when trying run shell script contains ls \r\n line separators (it looks trashed because carriage return causes terminal overwrite parts of line):

: not foundsh: ls 

there several questions per day on stackoverflow people being bitten this, such here, here , here.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -