char ch;
InputStreamReader in = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(in);ch = (char)in.read();和ch = (char)br.read();这两句有什么区别?即InputStreamReader.read()和BufferedReader.read()方法的区别是什么?
InputStreamReader in = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(in);ch = (char)in.read();和ch = (char)br.read();这两句有什么区别?即InputStreamReader.read()和BufferedReader.read()方法的区别是什么?
= 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.
-------------------------public class InputStreamReaderextends ReaderAn InputStreamReader is a bridge from byte streams to character streams: It reads bytes and decodes them into characters using a specified charset. The charset that it uses may be specified by name or may be given explicitly, or the platform's default charset may be accepted. Each invocation of one of an InputStreamReader's read() methods may cause one or more bytes to be read from the underlying byte-input stream. To enable the efficient conversion of bytes to characters, more bytes may be read ahead from the underlying stream than are necessary to satisfy the current read operation. For top efficiency, consider wrapping an InputStreamReader within a BufferedReader. For example: BufferedReader in
= new BufferedReader(new InputStreamReader(System.in));
Read text from a character-input stream, buffering characters so as to provide for the efficient reading of characters, arrays, and lines. ------------------------------
InputStreamReader:
An InputStreamReader is a bridge from byte streams to character streams: It reads bytes and decodes them into characters using a specified charset.