开发者

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.

The path of the image is: /mnt/sdcard/projFolder/1090901/-23686809809

Following is the code to download image :

    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

Android getting FileNotFound Exception, even if file exists


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜