我从我的业务数据:FileNotFoundException异常:EACCES(拒绝)
JSONObject userGuid = new JSONObject();
userGuid.put("userGuid", id);
Bitmap bitmap = null;
String response = HttpUtil.post(mService + "GetUser", userGuid.toString(), mCookie);
JSONObject result = new JSONObject(response).getJSONObject("User");
String temp = result.getJSONArray("UserImage").toString();
在接收到的数据
,有一个的Base64图像的用户,我得到了它,将其转换为arryByte,然后我将其转换为的InputStream:
byte[] tmp = Base64.decode(temp, Base64.DEFAULT);
InputStream is = new ByteArrayInputStream(tmp);
我想将它写入文件通过的OutputStream:
OutputStream os = new FileOutputStream(f);
,但我得到这个错误:
java.io.FileNotFoundException: /storage/emulated/0/fcImages/581864034: open failed: EACCES (Permission denied)
在清单中,我添加这些权限:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET"/>
什么是你的主意吗?
编辑 我以这种方式创建文件:
public class FileCache {
private File cacheDir;
public FileCache(Context context) {
if((Environment
.getExternalStorageState()).equals(Environment.MEDIA_MOUNTED)) {
cacheDir = new File(Environment.getExternalStorageDirectory(), "fcImages");
} else {
cacheDir = context.getCacheDir();
}
if(!cacheDir.mkdirs()) {
cacheDir.mkdirs();
}
}
public File getFile(String id) {
String filename = String.valueOf(id.hashCode());
File f = new File(cacheDir, filename);
return f;
}
女巫Android操作系统的版本,你测试? –
我正在使用API 23 – sayres
可能您需要阅读本文。在尝试“使用”它之前,你必须在代码中请求许可:)。 https://developer.android.com/training/permissions/requesting.html –