Android getting FileNotFound Exception, even if file exists
As the title suggests I am getting "FileNotFoundException"
even if image exists in SDCard, and even with all my efforts I am not able to find any reason for it. I have the permission in manifest for writing on external storage. Also this occurs for only certain images, so it's quite complicating the issue.
URL Url = new URL(url);
URLConnection urlConn = Url.openConnection();
if(!enoughSpaceLeft(urlConn.getContentLength())){
onError(NoSpaceError);
break;
}
InputStream is = Url.openStream();
OutputStream os = new FileOutputStream(file);
byte[] b = new byte[1024];
int length;
while ((length = is.read(b)) != -1)
os.write(b, 0, length);
os.close();
is.close();
I am attaching the image that is creating 开发者_如何学Cproblem , it's actually a QR code
You should have write-to-SD card permissions.
One possible reason is that it won't be possible to read from the SD card if the phone is connected to a computer and mass storage mode is on.
精彩评论