Question

I am trying to open a file from the assets as a FileInputStream using

new FileInputStream("file:///android_asset/file.html");

But it always throws a FileNotFoundException, even thought the file is there.

I know I can open files from assets using getAssets() and so on (and this works for the same file), but shouldn't this method be also working?

PS. I have set my app to request permission for file accessing.

Was it helpful?

Solution

Assets are stored relative to your app location and that is why absolute paths will not work. You need to use AssetManager to retrieve an InputStream to your assets as needed. getAssets() should work just fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top