Kotlin Program to Convert InputStream to String. In this program, you’ll learn to convert the input stream to a string using InputStreamReader in Kotlin.In the below program, the input stream is created from a String and stored in a variable stream.
Kotlin Program to Convert InputStream to String
Source Code
import java.io.*
fun main(args: Array<String>) {
val stream = ByteArrayInputStream("Hello are you Here!".toByteArray())
val sb = StringBuilder()
var line: String?
val br = BufferedReader(InputStreamReader(stream))
line = br.readLine()
while (line != null) {
sb.append(line)
line = br.readLine()
}
br.close()
println(sb)
}
Output
Kotlin Program to Convert InputStream to String