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时,是这样的
当你创建bufferedinputstreamWhen 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?
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.
Its cache and your own cache are not the same concept. The general process is as follows.
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.
当你创建
bufferedinputstream
When you createbufferedinputstream
, it willimmediately 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?
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.
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