How can I transalte this to Kotlin from Java: ``` ...
# announcements
o
How can I transalte this to Kotlin from Java:
Copy code
while ((inputLine = input.readLine()) != null) {
Log.d(TAG, inputLine);
   }
d
In IntelliJ just past it in and the IDE will convert it for U.
o
unfortunatelly, no
s
Assuming that there is actually a variable
inputStream
of type InputStream that your BufferedReader
input
is initialized on use:
Copy code
val inputStream = ...
inputStream.bufferedReader().useLines { lines ->
    for(line in lines) {
        Log.d(TAG, line)
    }
}
This will also close the inputStream.
o
Yes. There should be 2 variables. I'll try your code. Thanks
p
You can also write it like that if you need while loop 🙂
Copy code
while (true) {
    val inputLine = input.readLine() ?: break
    Log.d(TAG, inputLine);
}
👍 1
1
o
hm, I like this way)