I'm trying to change this while loop into a for loop and I'm not getting particularly far. I am new ish to programming, so apologies if this is a trivial task.
while (read < fileBytes.length
&& (numRead = diStream.read(fileBytes, read, fileBytes.length - read)) >= 0)
{
read = read + numRead;
}
Try to use this :
start_value = //....
for (read = start_value; read < fileBytes.length
&& (numRead = diStream.read(fileBytes, read, fileBytes.length - read)) >= 0;
read += numRead) {
//Your actions
}
I'm a C# Programmer, but I will write code which is very similar to what you need.
for (int read = 0; read < fileBytes.length;) {
numRead = diStream.read(fileBytes, read, fileBytes.length - read);
if (numRead >= 0) {
read = read + numRead;
}
}
for(numRead = diStream.read(fileBytes, read, fileBytes.length - read);
read < fileBytes.length && numRead >= 0;
numRead = diStream.read(fileBytes, read, fileBytes.length - read)) {
read = read + numRead;
}