How to use while loop with responseInputStream.read in kotlin android
here added responseInputStream read while loop .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())
Kotlin don't like as java, you can't composing multi-expression in a single line. you should break one-line expressions into multi-lines, for example:
while(true){
val i= responseInputStream.read(byteContainer);
if(i==-1) break;
responseStringBuffer.append(String(byteContainer, 0, i))
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With