muddy83
muddy83

Reputation: 3

Why isn't "carriage return" buffered in Java SE8?

Consider the following code, and let us say that the input character is "Z", which in UNICODE equals to 90.

//*********************************
// Read a character from the keyboard.

class KbIn {

  public static void main(String[] args)

   throws java.io.IOException {

     int ch, ch2, ch3;

     System.out.println("Press a key followed by ENTER");

     ch= System.in.read(); // get a character

     ch2= System.in.read(); // get a character

     ch3= System.in.read(); // get a character

     System.out.println(ch);

     System.out.println(ch2);

     System.out.println(ch3);

  }

}
//***************************

I would expect that the console output would be:

90 13 10

This corresponds to Z (90), carriage return (13) and a line feed (10). Instead I get to insert Z twice, and the output is:

90 10 90

So my question is: Does this mean that "carriage return is not buffered"?

I'am using a Terminal on a MacBook (Sierra OS).

Upvotes: 0

Views: 42

Answers (1)

Jeremy Gurr
Jeremy Gurr

Reputation: 1623

Macs only use linefeeds to end lines, not carriage returns. Windows behaves differently, and uses carriage returns.

Upvotes: 1

Related Questions