Do not confuse what the default behavior of InputStream is and what most of its subclasses do. The principle of OO design is that subclasses can change the behavior of a method for this implementation.
From InputStream - read (byte []) repeatedly calls read ().
public int read(byte b[], int off, int len) throws IOException {
From BufferedInputStream - read (byte []) does not call read ().
public synchronized int read(byte b[], int off, int len) throws IOException {
From FileInputStream - read (byte []) does not call read ().
public int read(byte b[], int off, int len) throws IOException { return readBytes(b, off, len); } private native int readBytes(byte b[], int off, int len) throws IOException;
While an InputStream will read one byte at a time, almost all implementations pass read (byte []) to the same method in the base stream.
Note: read implementations (byte [], int, int) are different in all three cases.
What I want to say more clearly is: Let's say I want to read 20 bytes, Reading one byte at a time gets into the base stream (for example, the file system) every time in the loop, which means 20 times. an array of 20 bytes at a time, i.e. using read (byte [] 20). Now, to get into the base stream (for example, the file system) once or 20 times .. ?? (since it is given: read (byte [] b) the method will also call the read () method again 20 times)
If you use BufferedInputStream or FileInputStream, a single read (byte []) results in the system call itself to read in bytes [].