When reading from a pseudo-terminal via java, I'm seeing "\n\r" in the text. What is that representative of? Note its not "\r\n" which I'm familiar with.
1 Answer
\n
is a line feed (ASCII code 10), \r
is a carriage return (ASCII code 13).
Different operating systems use different combinations of these characters to represent the end of a line of text. Unix-like operating systems (Linux, Mac OS X) usually use only \n
. MS-DOS and Windows use \r\n
(carriage return, followed by a line feed).
The code you're using uses \n\r
(line feed, carriage return). There are operating systems that use that sequence, but probably it's a mistake and it should have been \r\n
.
See Newline on Wikipedia.
If you're programming in Java and you want to know what the newline sequence is for the operating system that your program is running on, you can get the system property line.separator
:
String newline = System.getProperty("line.separator");
\r
is a carriage return which often means that the cursor should move to the leftmost column, while\n
is a line feed which moves the cursor to the next line.