In our project sometimes when we use InputStream.read(byte[] b) method, there is some error.
When we use
byte[] b = new byte[1024];
int len = -1;
while ((len = io.read(b, 0, 1024)) != -1) {
response.getOutputStream().write(b, 0, len);
}
then it goes well.
I found the source code, which is amazing
public int read(byte b[]) throws IOException {
return read(b, 0, b.length);
}
Inside read method, it calls read(b, 0, b.length). In our project, b.length equals 1024, so why do we get the error?
Does anybody know the difference between these two methods? Thanks