下面是java doc关于InputStreamReader的解释:
An 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));
上面也说明了,把字节流转换成字符流是为了提高操作的效率,有需求就有提供者。
至于把字符---->字节的转换,你发现你没见过相应的用法吧,一般都是直接获取InputStream或者把InputStream继续封装。
因为对字符的操作比直接操作字节方便高效,也没人愿意字符流转换成字节流。 |