Easy File Copy in Kotlin
Sunday, June 24, 2018 |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:
1
File("/path/to/destination").writeBytes(File("/path/to/source").readBytes())
That could even be an extension function itself:
1
fun File.copyFile(dest: File): Unit = dest.writeBytes(this.readBytes())