Last active
May 29, 2023 04:57
-
-
Save Atsumi3/92e690700a5c3dda5270295bb7fe2b9f to your computer and use it in GitHub Desktop.
[Android] assetsにあるファイルをキャッシュ領域にコピーし、Fileとして扱えるようにするスニペット
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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