9

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
  • A bit more context would help. \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. Dec 6, 2012 at 14:15

1 Answer 1

20

\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");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.