java - Why it is advisable to wrap BufferReader around InputStreamReader? -


bufferreader br = new bufferedreader(new inputstreamreader(system.in)); 

please explain why inputstreamreader(system.in) passed in bufferreader().

the docs answer question.

in general, each read request made of reader causes corresponding read request made of underlying character or byte stream. therefore advisable wrap bufferedreader around reader read() operations may costly, such filereaders , inputstreamreaders.

for example,

bufferedreader in = new bufferedreader(new filereader("foo.in")); 

will buffer input specified file. without buffering, each invocation of read() or readline() cause bytes read file, converted characters, , returned, can inefficient.


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -