我试图在手机的内部存储器中存储一个PNG文件,但尝试了很多不同的方法后,我遇到了很多问题。只读文件系统
I'm使用此代码:
private void storeImage(Bitmap image, String nombre) {
try {
File file = new File(nombre+".png");
file.createNewFile();
FileOutputStream fos = new FileOutputStream(file);
image.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.close();
} catch (FileNotFoundException e) {
Log.d(TAG, "File not found: " + e.getMessage());
} catch (IOException e) {
Log.d(TAG, "Error accessing file: " + e.getMessage());
}
}
但doesn't工作,因为我得到这个消息logcat中:
访问文件时出错:打开失败:EROFS(只读文件系统)
我不知道如何更改文件的权限,或者如果有更好的方法来保存在手机中的PNG文件。
谢谢!
<使用许可权的android:NAME = “android.permission.WRITE_EXTERNAL_STORAGE”/><使用许可权的android:NAME =“android.permission.WRITE_INTERNAL_STORAGE “/>你必须添加权限 –