input/output 流和普通的 reader 和 writer 有什么区别,它们的类型有什么区别?

What's the difference between input/output streams and ordinary reader and writer and what's the difference between their types?

现在我似乎不明白那些流 (Input/Output) 和普通的 writerreader 甚至 scanner 和 [= 之间的区别15=] ...

为什么 InputStream 有很多像 DataInputStreamBufferedInputStream 这样的子 类 和所有那些乱七八糟的东西(OutputStream 也一样当然)...

最后一件事,如果缓冲区那么好(所以我读到)并且高效,为什么有人会使用任何其他 input/output 方式(为什么他们甚至被制作?)

read/write bytes, while Readers read and Writers write character data. Since underneath it all you always have bytes when doing I/O, this means that readers and writers do an additional step of converting 个字节流式传输到字符。

两种情况(我刚刚链接的那些)都有抽象的超级类,还有各种子类,不仅仅是流——你可以在Javadoc中自己看到,每个页面列出所有这些的子类。

如果你想在处理之前先收集一大块数据,缓冲区就很有意义。例如,一个很好的理由是,如果您一次 read/write 一大块数据,而不是 reading/writing 每个 byte/character 单独访问,磁盘访问效率更高。但是,当然,在许多不同的情况下您可能想要做 I/O -- 没有一种适合所有情况,因此有不同的 类 适合这些不同的情况。

制作缓冲版本的原因完全是面向对象编程的基本原则:通过解耦功能,您可以降低复杂性 mechanisms/designs 同时解决更广泛的可能应用程序,如上所述.