
这个问题已经在这里有了答案: > Best way to translate this java code into kotlin 3个
如何在Kotlin AndroID中使用while循环与responseinputStream.read
这里添加了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(byteContain全部内容,希望文章能够帮你解决如何在kotlin android中用responseInputStream.read编写while循环–while((i = responseInputStream.read(byteContain所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)