Java – does FileInputStream already use buffers?

When I use FileInputStream to read an object (such as a few bytes), does the underlying operation involve:

1) Read the whole disk, so that if I do another read operation later, it does not need a real disk read, because this part of the file has been removed in the last read operation?

or

2) Since FileInputStream does not perform any buffering, new disk access should be performed. Instead, bufferedinputstream should be used to achieve the effect of (1)?

I think because FileInputStream uses read system calls and it only reads a set of pages from the hard disk, it must do some buffering

Solution

FileInputStream will make the underlying native system call Most operating systems do their own buffering for this Therefore, it does not need to find a real disk for each byte However, you still need the cost of making native OS calls, which is expensive So bufferedstream will be better However, in order to read a small amount of data (as you said, a few bytes or even a few bytes), any one should be OK, because the number of OS calls will not be so different

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>