如何在kotlin android
中使用带有responseInputStream.read的while循环这里添加了responseInputStream read while循环.kt
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())
答案 0 :(得分:4)
Kotlin不喜欢java,你不能在单行中编写多个表达式。你应该将单行表达式分解为多行,例如:
while(true){
val i= responseInputStream.read(byteContainer);
if(i==-1) break;
responseStringBuffer.append(String(byteContainer, 0, i))
}