How to write while loop with responseInputStream.read in kotlin android - - while ((i = responseInputStream.read(byteContainer)) -
this question has answer here:
- best way translate java code kotlin 2 answers
how use while loop 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 java, can't composing multi-expression in single line. should break one-line expressions multi-lines, example:
while(true){ val i= responseinputstream.read(bytecontainer); if(i==-1) break; responsestringbuffer.append(string(bytecontainer, 0, i)) }
Comments
Post a Comment