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()方法的区别是什么?

解决方案 »

  1.   

    public class BufferedReaderextends ReaderRead 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.
    -------------------------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));
      

  2.   

    BufferedReader:
    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.