I am trying to save files from the asset folder to the android device's public directory e.g. "Downloads". Normal file read-write doesn't seem to work. How to do it?
I have tried this How to copy files from 'assets' folder to sdcard? but this didn't work.
fun copy() {
val bufferSize = 1024
val assetManager = context.assets
val assetFiles = assetManager.list("")
assetFiles.forEach {
val inputStream = assetManager.open(it)
val outputStream = FileOutputStream(File(this.getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS), it))
try {
inputStream.copyTo(outputStream, bufferSize)
} finally {
inputStream.close()
outputStream.flush()
outputStream.close()
}
}
}