Coming Up for Air

Easy File Copy in Kotlin

Copying files in Java is, I think, header than it seems it should be. Typically, I see that done with, say, a ByteArrayInputStream and a ByteArrayOutputStream . Thanks to Kotlin’s extension function capabilities, this operation is a one-liner:


That could even be an extension function itself:

fun File.copyFile(dest: File): Unit = dest.writeBytes(this.readBytes())
tags: Kotlin


Sample quote

Quote source