java - Why does System.in.read() wait till the user presses enter? -
system.in.read()used read single character.
then why allow user enter many characters can until presses enter?
why doesn't stop presses key , returns character?
char ch = (char)system.in.read(); if user enter "example" , press enter, takes ch e. , discards other characters.
if there multiple read(), messes whole thing.
so, why doesn't take single character , return?
system.in of type bufferedinputstream. type of stream caches input data until newline character recognized. following snippet shows type in output.
system.out.println(system.in.getclass());
Comments
Post a Comment