What is the difference between FileInputStream and bufferedinputstream in Java?
What is the difference between FileInputStream and bufferedinputstream in Java?
Solution
Main differences:
>Bufferedinputstream is buffered, but FileInputStream is not. > Bufferedinputstream reads from another InputStream, but FileInputStream reads from file1
In fact, this means for FileInputStream Each call to read () will execute a system call (expensive)... And most of them are to bufferedinputstream The call to read () returns data from the buffer In short, if you are doing "small" reads, putting bufferedinputstream on the stream stack will improve performance
>This is relevant for most purposes / use cases. > There are other things (such as mark / reset / skip), but these are professional... > for more details, please read the JavaDocs... And the source code
1 – or more precisely, from an object 1) has a name in the "file system" namespace of the operating system, and 2) the operating system allows you to read as a byte sequence This may include equipment, named pipes, and various other things that may not be considered "files" It is worth noting that some content cannot be read using FileInputStream