+-
如何在kotlin android中用responseInputStream.read编写while循环–while((i = responseInputStream.read(byteContainer))[复制]
这个问题已经在这里有了答案:            >             Best way to translate this java code into kotlin                                    3个
如何在Kotlin Android中使用while循环与responseInputStream.read

my code for while loop in kotlin android

another one

这里添加了while循环.kt时读取的responseInputStream

                val responseInputStream = conn.inputStream
                val responseStringBuffer = StringBuffer()
                val byteContainer = ByteArray(1024)
                var i: Int
                while ((i = responseInputStream.read(byteContainer)) != -1) {
                    responseStringBuffer.append(String(byteContainer, 0, i))
                }
                Log.w("TAG", "res :" + responseStringBuffer.toString())
最佳答案
Kotlin不喜欢Java,您不能在一行中组成多重表达式.您应该将单行表达式分成多行,例如:

while(true){
  val i= responseInputStream.read(byteContainer);

  if(i==-1) break;

  responseStringBuffer.append(String(byteContainer, 0, i))
}
点击查看更多相关文章

转载注明原文:如何在kotlin android中用responseInputStream.read编写while循环–while((i = responseInputStream.read(byteContainer))[复制] - 乐贴网