Java BufferedOutputStream vs OutputStream [duplicate]

北城以北 提交于 2019-12-02 11:02:59

问题


What are the differences between BufferedOutputStream and OutputStream.

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.


回答1:


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.

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



来源:https://stackoverflow.com/questions/30283511/java-bufferedoutputstream-vs-outputstream

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