我從我的業務數據: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 –