MichelReap
MichelReap

Reputation: 5770

Can't open FileInputStream from assets

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.

Upvotes: 2

Views: 1884

Answers (1)

Anup Cowkur
Anup Cowkur

Reputation: 20553

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.

Upvotes: 3

Related Questions