java - bufferedinputstream也需要指定一个数组长度呀?并没有什么用呀?
PHP中文网
PHP中文网 2017-04-17 17:48:10
0
3
678

他与fileinputstream 的区别是什么呀?他不是自带缓冲区吗?为什么还需要指定一个byte数组?

PHP中文网
PHP中文网

认证0级讲师

reply all(3)
阿神

Its cache and your own cache are not the same concept. The general process is as follows.

When using inputstream without caching

Every time you read, the system performs a read operation to read out the data. If you specify a byte to read, it will read one byte, if you specify an array, it will read an array. The reading efficiency of your program and data is good. Very big relationship.

When using bufferedinputstream, it’s like thisbufferedinputstream时,是这样的

当你创建bufferedinputstream When you create bufferedinputstream, it will
immediately read the data and put it into the memory managed by jvm. Every time you read it, it will not read it in the system again. It will read the data in the memory, and then judge whether there is enough left in the memory. If not, it will direct the system to read the operation. Whether you are reading a byte or an array, the system will not necessarily be sure
Will operate the hard drive. The correlation between your program and data reading efficiency is very small.


Think about it from another perspective, If you use a stream without buffer, open the file and then close it immediately, the system will not make any data calls
, and the closing will be executed quickly. And if you use a buffered stream to open a file, even if it is closed immediately without reading, the closing will not be executed immediately, and the system has already read part of the data into the memory. It will be better than using it without buffering. The buffer efficiency is low.

Of course no one would be so bored that they would close the stream without reading it after creating it, right?

PHPzhong

There is no relationship between buffering and using arrays to receive content. It does not say that with buffering, there is no need for arrays to receive content.

Peter_Zhu

Because we hope to reuse this byte[], otherwise when faced with large data stream IO transmission, you will find that YGC will be very happy

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!