Could you help me figure out the streams. Why in the tutorials I find that when reading from a file, we use len != -1 (for example).And when reading from a stream and then writing to a stream, we use len> 0.What is the difference when reading?
PS The codes below are taken from examples
byte[] buffer = new byte[1024];
int len;
while ((len = in.read(buffer)) != -1) {
out.write(buffer, 0, len);
}
byte[] buf = new byte[8192];
int length;
while ((length = source.read(buf)) > 0) {
target.write(buf, 0, length);
}
}
UPD
UPD 2
You can also look at IOUtils.copy and Files.copy They are different too
UPD 3
I read that the read method does not return 0, or the available number of bytes, or -1. Thanks everyone