Kotlin — Copy (big) files

  • Getting an output stream from the destination file (where we are going to write the bytes from the original file).
  • Reading the bytes to copy from the original file.
  • Writing them in the output stream we previously opened and finally closing that stream.
Gets the entire content of this file as a byte array.This method is not recommended on huge files. It has an internal limitation of 2 GB byte array size.

Copying bigger files

  • Reading all the bytes of a big file at once, exceeding the API limitations
  • Creating a huge ByteArray which will also exceed API limitations
  • Create files filled with random bytes and then copy them
  • Generate a checksum for the original and the copied files to verify that the bytes were copied properly.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alessandro Mautone

Alessandro Mautone

Senior Android Engineer @WeTransfer 🤖 🇻🇪🇮🇹 Paraglider, Runner, Kayaker.