HttpURLConnection java.io.FileNotFoundException in android 5.0.2 -


i using below code downloading pdf file server , store sdcard. running fine on android 4.4 device. while not working on android 5.0.2 device.

public static string downloadfile(string fileurl, file directory){         try {              url url = new url(fileurl);             httpurlconnection urlconnection = (httpurlconnection)url.openconnection();             urlconnection.setrequestmethod("get");             urlconnection.setdooutput(false);             urlconnection.connect();               inputstream inputstream = urlconnection.getinputstream();             fileoutputstream fileoutputstream = new fileoutputstream(directory);             int totalsize = urlconnection.getcontentlength();              byte[] buffer = new byte[megabyte];             int bufferlength = 0;             while((bufferlength = inputstream.read(buffer))>0 ){                 fileoutputstream.write(buffer, 0, bufferlength);             }             fileoutputstream.close();             result = "true";         } catch (filenotfoundexception e) {             e.printstacktrace();             result = "false";         } catch (malformedurlexception e) {             e.printstacktrace();             result = "false";         } catch (ioexception e) {             e.printstacktrace();             result = "false";         }         return result;     } 

on line: inputstream inputstream = urlconnection.getinputstream(); got java.io.filenotfoundexception error.

i tried many things didnt work. me solved bug.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -