It's more efficient to read multiple bytes at a time:
public int read(byte[] data) throws IOException
public int read(byte[] data, int offset, int length) throws IOException
These methods block until there is some data available. Then
they read as many bytes as they can into b
, or
until they've read length
bytes.
Each returns the number of bytes actually read or -1 on end of stream.