Domanda

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.

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top