问题描述
对于电话内部存储器中存在的文件(其路径为/system/data/recf/pic.jpg),使用openInputStream()方法构造inputStream会引发FileNotFoundException.
For an existent file in the internal storage of the phone, path of which is /system/data/recf/pic.jpg, constructing inputStream using openInputStream() method throws FileNotFoundException.
这就是我在做的-
ContentResolver cr = context.getContentResolver();
InputStream inputStream = null;
Uri filename = Uri.parse("file:///system/data/recf/pic.jpg");
inputStream = cr.openInputStream(filename);
但是它抛出FileNotFoundException.我检查了文件是否存在.卡住了很长时间,请帮忙.谢谢.
But it is throwing a FileNotFoundException. I have checked that the file exists. Stuck for a long time, please help. Thanks.
推荐答案
就Android而言,设备的内部存储(电话存储)仍被视为外部存储.外部存储"可能是指可移动存储(例如SD卡)或不可移动的电话内部存储.
Device's Internal Storage (Phone Storage) is still considered External Storage in terms of Android. "External Storage" may refer to removable storage such as SD card or non-removable internal storage of phone.
内部存储空间"是指您应用的私有空间,不会与任何人(包括用户)共享.
"Internal Storage" refers to a private space of your app which is not shared with anyone, including the user.
因此,需要具有读写外部存储的权限.在Android M +上,需要实时权限.
Hence, permission to read from and write to External Storage was required. On Android M+, real-time permission was required.
这篇关于无法使用ContentResolver.openInputStream(Uri)读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!