本文介绍了Java BufferedOutputStream 与 OutputStream的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

BufferedOutputStream 和 OutputStream 有什么区别.

What are the differences between BufferedOutputStream and OutputStream.

我读到的是,对于大文件,bos 比 os 更快更好,但我真的不明白为什么.希望对这两个主题有一些澄清和见解.

What i've read is that bos is faster and better for large file than os but i don't really understand why. Hope to get some clarification and insight on these 2 topics.

推荐答案

由于 IO 操作成本较高,BufferedOutputStream 首先将它们写入缓冲区,然后将块写入底层 OutputStream.BufferedOutputStream 使用装饰器模式,它在运行时将额外的责任附加到 OutputStream.

AS IO operations are costlier, BufferedOutputStream first writes them in buffer and write the chunk on underlying OutputStream. BufferedOutputStream uses decorator patterns where it attaches the additional responisibilty at run time to OutputStream.

BufferedInputStream 也是如此,它读取块中的字节并将它们放入缓冲区.当实际的读操作发生时,它从那个缓冲区而不是像磁盘那样底层的 InputStream 读取,这是更昂贵的

Same is true for BufferedInputStream which reads the bytes in chunk and place them in buffer. When actual read operation occurs , it reads from that buffer instead of underlying InputStream like disk which is costlier

这篇关于Java BufferedOutputStream 与 OutputStream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-18 07:51