java - Why doesn't BufferedReader buffer the input? -


i ran following example:

public static void main(string[] args) throws ioexception{         reader reader = new bufferedreader(new inputstreamreader(system.in));         int character;         do{             character = reader.read();             system.out.println(character);         } while(character != '\n');     } 

and confused behaviour. thought default buffer size of bufferedreader large enough hold more 1 character.

but, when entered

a__new_line__ 

it causes character printed along new line. why? expected buffer not full, therefore there should no output.

bufferedreader buffers data when possible. in case there no data buffer. so, returns enter immediately. bufferedreader useful when used large streams such file (fileinputstream) , in cases read method returns 1 character while behind scene, bufferedreader reads more data (depends on buffer size) related inputstream , caches improve performance.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -