gpt4 book ai didi

java - BufferedInputStream 和 java.nio.Buffer 有什么区别?

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:13:54 25 4
gpt4 key购买 nike

我们可以通过装饰一个FileInputStream来得到一个BufferedInputStream。而从 FileInputStream.getChannel 获取的 Channel 也可以将内容读入到 Buffer 中。

那么,BufferedInputStreamjava.nio.Buffer 有什么区别?即,我什么时候应该使用 BufferedInputStream 什么时候应该使用 java.nio.Bufferjava.nio.Channel

最佳答案

Getting started with new I/O (NIO) ,文章摘录:

A stream-oriented I/O system deals with data one byte at a time. An input stream produces one byte of data, and an output stream consumes one byte of data. It is very easy to create filters for streamed data. It is also relatively simply to chain several filters together so that each one does its part in what amounts to a single, sophisticated processing mechanism. On the flip side, stream-oriented I/O is often rather slow.

A block-oriented I/O system deals with data in blocks. Each operation produces or consumes a block of data in one step. Processing data by the block can be much faster than processing it by the (streamed) byte. But block-oriented I/O lacks some of the elegance and simplicity of stream-oriented I/O.

关于java - BufferedInputStream 和 java.nio.Buffer 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39422029/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com