Write InputStream To File

val outputStream = FileOutputStream(outputFile)// the following should work as well // val outputStream = outputFile.outputStream()inputStream.use { input ->    outputStream.use { output ->        input.copyTo(output)    }}

Convert large string into InputStream.

val input = "I am String"val inputStream = ByteArrayInputStream(input.toByteArray(UTF_8))

If the InputStream is a file, you can use File.copyTo instead.

inputFile.copyTo(outputFile, true)

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.