Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write while loop with responseInputStream.read in kotlin android - - while ((i = responseInputStream.read(byteContainer)) [duplicate]

How to use while loop with responseInputStream.read in kotlin android

my code for while loop in kotlin android

another one

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())
like image 339
A Maharaja Avatar asked Jul 01 '17 05:07

A Maharaja


1 Answers

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))
}
like image 161
holi-java Avatar answered Nov 03 '22 06:11

holi-java