Skip to content

Instantly share code, notes, and snippets.

@Atsumi3
Last active May 29, 2023 04:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Atsumi3/92e690700a5c3dda5270295bb7fe2b9f to your computer and use it in GitHub Desktop.
Save Atsumi3/92e690700a5c3dda5270295bb7fe2b9f to your computer and use it in GitHub Desktop.
[Android] assetsにあるファイルをキャッシュ領域にコピーし、Fileとして扱えるようにするスニペット 
fun Context.loadFileFromAssets(fileName: String): File {
return File(cacheDir, fileName)
.also {
if (it.exists()) it.delete()
it.outputStream().use { cache ->
assets.open(fileName).use { inputStream ->
inputStream.copyTo(cache)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment