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
Post a Comment