编程语言
首页 > 编程语言> > java-将while循环更改为for循环

java-将while循环更改为for循环

作者:互联网

我正在尝试将此while循环更改为for循环,并且我走的还不是很远.我是编程新手,如果这是一件微不足道的任务,请您道歉.

while (read < fileBytes.length
       && (numRead = diStream.read(fileBytes, read, fileBytes.length - read)) >= 0)
{
    read = read + numRead;
}

解决方法:

我是C#程序员,但是我将编写与您需要的代码非常相似的代码.

for (int read = 0; read < fileBytes.length;) {
    numRead = diStream.read(fileBytes, read, fileBytes.length - read);
    if (numRead >= 0) {
        read = read + numRead;
    }
}

标签:while-loop,for-loop,java
来源: https://codeday.me/bug/20191111/2019801.html