我正在尝试从外部存储(图片目录)加载 .gif 图像,但我使用以下代码得到“找不到文件异常” 。
InputStream mInputStream = null;
AssetManager assetManager = getResources().getAssets();
try {
mInputStream = assetManager.open(getExternalFilesDir(Environment.DIRECTORY_PICTURES).getAbsolutePath().concat("/01.gif"));
} catch (IOException e) {
e.printStackTrace();
}
我也使用手动路径进行了测试,但遇到了同样的异常
mInputStream = assetManager.open("file:///mnt/sdcard/Android/data/com.shurjo.downloader/files/Pictures/01.gif");
清单文件中有 SD 卡的写/读权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
请帮助我如何从外部存储打开文件作为 InputStream。提前致谢。
注意:我在模拟器上测试过,图片文件夹下有一个文件01.gif(请看手册路径)。我可以创建目录并将文件放在这些目录中,但无法通过输入流访问这些文件。