In Kotlin, how do I read the entire contents of an InputStream into a String?
Kotlin has a specific extension just for this purpose. The simplest: val inputAsString = input.bufferedReader().use { it.readText() } // defaults to UTF-8 And in this example, you could decide between bufferedReader() or just reader(). The call to the function Closeable.use() will automatically close the input at the end of the lambda’s execution. Further reading: If … Read more