0
pls explain buffered reader
3 ответов
+ 2
Reads text from a character-input stream, buffering characters so as to provide for the efficient reading of characters, arrays, and lines.
The buffer size may be specified, or the default size may be used. The default is large enough for most purposes.
In general, each read request made of a Reader causes a corresponding read request to be made of the underlying character or byte stream. It is therefore advisable to wrap a BufferedReader around any Reader whose read() operations may be costly, such as FileReaders and InputStreamReaders. For example,
BufferedReader in
= new BufferedReader(new FileReader("foo.in"));
will buffer the input from the specified file. Without buffering, each invocation of read() or readLine() could cause bytes to be read from the file, converted into characters, and then returned, which can be very inefficient.
Programs that use DataInputStreams for textual input can be localized by replacing each DataInputStream with an appropriate BufferedReader.
0
the distinguishing point about a buffer is that the data does print until all the characters in the stream are recieved.
0
buffered reader is used to read a complete line at a time from file or from input device.
to read a line from file use:
BufferedReader br = new BufferedReader(new FileReader("file_name"));
String line = br.readLine();
to read from input device:
BufferedReader br = new BufferedReader(new FileReader(System.in));
String line = br.readLine();