Reader/Writer与InputStream/OutputStream的区别

有些话、适合烂在心里 提交于 2019-12-03 19:19:34

1. Readers and writers are like input streams and output streams. The primary difference lies in the
fundamental datatype that is read or written; streams are byte-oriented, whereas readers and
writers use characters and strings.

2. The reason for this is internationalization. Readers and writers were designed to allow programs
to use a localized character set and still have a stream-like model for communicating with
external devices.

3. These are analogous to the read( ) methods defined for InputStream. For example, read( )
still returns an integer. The difference is that, instead of data values being in the range of 0-255
(i.e., single bytes), the return value is in the range of 0-65535 (appropriate for characters, which
are 2 bytes wide).

4. Instead, readers and writers can be used as a layer on top of streams™ most readers have a
constructor that takes an InputStream as an argument, and most writers have a constructor
that takes an OutputStream as an argument.

1.主要区别在于被读和被写入的基本数据类型;InputStream OutputStream 是面向字节的,Reader Writer 使用的字符和字符串。

2.国际化:Reader Writer允许的程序使用本地化的字符集,仍然有流的特性。

3.Reader定义上类似InputStream的。例如,Reader还是返回一个整数。所不同的是,代替数据值在0-255的范围内(即单字节),返回值是在0-65535之间(适合字符,2个字节宽)。

4.大多数Reader 有一个构造函数的InputStream作为参数,并且大多数Writer 有一个构造函数这需要一个OutputStream作为参数。

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!