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:

File("/path/to/destination").writeBytes(File("/path/to/source").readBytes())

That could even be an extension function itself:

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

Quotes

Sample quote

Quote source