So I just started using Kotlin for Android and converted my Android codes to Kotlin.
In one of the conversions, I came across a BufferedReader, which I usually write in Java as follows:
String result = ""; String line = ""; BufferedReader reader = new BufferedReader(someStream); while ( (line = reader.readLine()) != null ) { result += line; }
But in Kotlin it seems that Kotlin does not allow me to assign values to variables in conditions.
Currently, I have written code as follows:
val reader = BufferedReader(someStream) var line : String? = "" while (line != null) { line = reader.readLine() result += line }
which I do not find so elegant and a feeling of foreboding, despite the use of Kotlin.
What would be the best way to use BufferedReader in Kotlin?
source share