android - OpenInputStream 返回文件未找到异常但文件在那里

标签 android

我正在尝试从 SD 卡缩放位图并将其写入手机内存。然后稍后将其解码以将其添加到 HashMap

问题是我收到文件未找到异常,尽管路径正确且缩放图像存在(我检查过)

这里是保存部分

        Bitmap yourSelectedImage = BitmapFactory.decodeStream(imageStream, null, options );         
        File imageRootPath = getFilesDir();
        File imageRoot = new File(imageRootPath, imagUri.getLastPathSegment()+".png");
        FileOutputStream out = new FileOutputStream(imageRoot);
        yourSelectedImage.compress(Bitmap.CompressFormat.PNG, 90, out);

这是我读取文件时的部分

try {
Uri mainImgeUri = Uri.parse(imageRoot.toString());
File imageFile = new File(mainImgeUri.toString());
if(imageFile.exists()){
   System.out.println("it does");
}
InputStream imageStream = ListPropertiesBaseActivity.this.getContentResolver().openInputStream(mainImgeUri); // I am getting file not found error

Bitmap yourSelectedImage =BitmapFactory.decodeStream(imageStream);
hmBitmap.put(ID, yourSelectedImage);
imageStream.close();
} catch (Exception e) {

e.printStackTrace();
}

难道OpenInputStream 无法读取手机内存?还是保存出来的图像不好?

虽然我能够通过手动浏览到文件并打开它来查看它

请注意,System.out.Println 已执行,这意味着文件存在

最佳答案

您是否尝试过记录 imageStream 以查看 uri 实际是什么?

关于android - OpenInputStream 返回文件未找到异常但文件在那里,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15117670/

相关文章:

android - Kivy 播放音频不工作

android - React Native RCTNetworking.sendRequest 有 6 个参数,预期为 7

android - FragmentStatePagerAdapter 重复 ActionBar 菜单项

android: CheckedTextView 不能检查?

java - 主 Activity 回收器 View 上未设置行布局

android - 为什么 Cursor 丢失了 sqlite 的排序 DESC

android - 布局内的 OpenGL View

android - 我可以将 native GoogleMap 添加到我的 Cordova 混合应用程序吗?

java - android文件选择器不工作

从任务管理器中终止时,Android GCM 未收到消息