I am trying to read zip from zip file programitically.
val f = File("src/main/files/zipfile.zip")
val zis = ZipInputStream(FileInputStream(f))
but i got error.
Caused by: java.io.FileNotFoundException: src/main/files/zipfile.zip (No such file or directory)
Why it doesn't see this file if it is on this path?
CodePudding user response:
It's not on this path in your compiled app. That's not a valid asset directory, and the files there will not be in your compiled app.
If you want to include a raw file in your app, put it in src/main/assets
. And to read it, you need to get it via context.assets
For example, in a Fragment:
val zipFileStream = requireContext().assets.open("zipfile.zip")
val zis = ZipInputStream(zipFileStream)
although you most likely should be reading files in a ViewModel so the contents can persist through a screen rotation.