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 wrapbufferedreader
aroundreader
read()
operations may costly, suchfilereaders
,inputstreamreaders
.for example,
bufferedreader in = new bufferedreader(new filereader("foo.in"));
will buffer input specified file. without buffering, each invocation of
read()
orreadline()
cause bytes read file, converted characters, , returned, can inefficient.
Comments
Post a Comment