Reading File From Uri Gives Java.io.filenotfoundexception: Open Failed: Enoent
When picking an image using an ACTION_GET_CONTENT intent, I get a URI that I can't open the file from. If I try to open the file, like this: InputStream in = new FileInputStream(ne
Solution 1:
If I try to open the file, like this:
That will not work for most modern Android devices. Most likely, you received a content:
Uri
. This is fairly normal on newer versions of Android. Future versions of Android might block file:
Uri
values.
I need to get the file to do decoding to make it smaller.
There does not have to be a file associated with a given Uri
. That Uri
might point to:
- A local file on external storage
- A local file on internal storage for the other app
- A local file on removable storage
- A local file that is encrypted and needs to be decrypted on the fly
- A stream of bytes held in a
BLOB
column in a database - A piece of content that needs to be downloaded by the other app first
- ...and so on
Use a ContentResolver
and openInputStream()
to get an InputStream
on the content pointed to by the Uri
. Then, pass that to your decoding logic, such as BitmapFactory
and its decodeStream()
method.
Post a Comment for "Reading File From Uri Gives Java.io.filenotfoundexception: Open Failed: Enoent"