Java 将位图保存到SD卡时FileNotFoundException
我试图将“viewBitmap”保存到SD卡中 这是我的密码:Java 将位图保存到SD卡时FileNotFoundException,java,android,fileoutputstream,Java,Android,Fileoutputstream,我试图将“viewBitmap”保存到SD卡中 这是我的密码: try{ String mPath = Environment.getExternalStorageDirectory().toString(); imageFile = new File(mPath, "/snapshot.png"); FileOutputStream outputStream = new FileOutputStream(imageFile); viewBitmap.compress(Bitmap.Compre
try{
String mPath = Environment.getExternalStorageDirectory().toString();
imageFile = new File(mPath, "/snapshot.png");
FileOutputStream outputStream = new FileOutputStream(imageFile);
viewBitmap.compress(Bitmap.CompressFormat.JPEG,100,outputStream);
outputStream.flush();
outputStream.close();
Toast.makeText(Share.this, "Collage was saved.",Toast.LENGTH_SHORT).show();
}catch(Throwable e) {
e.printStackTrace();
}
在“FileOutputStream outputStream=new FileOutputStream(imageFile);”行,引发异常:
在您的AndroidManifest.XML文件中,是否添加了权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
如果设备运行的是Android 6.0(API级别23)或更高版本,且应用程序的targetSdkVersion为23或更高版本,请参阅以在运行时请求权限。在提出问题之前,您甚至没有将异常复制粘贴到搜索栏中。您正在将文件保存到存储器中,这在新的android API中是一个安全的过程。对于此类敏感的应用程序功能,您必须从代码中获取运行时权限!这就是错误所说的获取许可请确定我会记得先将我的异常复制并粘贴到google中。Thanks@Pawel,我想他吸取了教训。乔·多伊,你下次必须做作业。这是我给你的一票,你可以继续提问。继续前进!