android - FileNotFoundException when calling HttpURLConnection getInputStream -
i have app want update private server. code below should download new apk file server , write sdcard app can update from.
i'm getting filenotfoundexception. file exist on server.
any ideas why may happening?
thanks
public void updateapp(string version){ try { version = version.trim(); string urlwithversion = "http://cfweb.yourofficeanywhere.co.uk/entryactivityv" + version + ".apk"; url url = new url(urlwithversion); httpurlconnection c = (httpurlconnection) url.openconnection(); c.setrequestmethod("get"); c.setdooutput(true); c.connect(); log.e(tag, " httpurlconnection = connected"); string path = environment.getexternalstoragedirectory() +"/"; file file = new file(path); file.mkdirs(); log.e(tag, "mkdirs()"); file outputfile = new file(file, "app.apk"); fileoutputstream fos = new fileoutputstream(outputfile); log.e(tag, "fos"); inputstream = c.getinputstream(); log.e(tag, "c.getinputstream()"); byte[] buffer = new byte[1024]; int len1 = 0; while ((len1 = is.read(buffer)) != -1) { log.e(tag, "update file size = " + len1); fos.write(buffer, 0, len1); } log.e(tag, "update file size = " + len1); fos.close(); is.close(); intent intent = new intent(intent.action_view); intent.setdataandtype(uri.fromfile(new file(environment.getexternalstoragedirectory() + "app.apk")), "application/vnd.android.package-archive"); intent.setflags(intent.flag_activity_new_task); nfcscanneractivity.this.startactivity(intent); } catch (exception e) { log.e(tag, "update error = " + log.getstacktracestring(e)); } } //end of updateapp
.
09-10 16:00:59.504: e/nfcscanneractivity(18814): httpurlconnection = connected 09-10 16:00:59.504: e/nfcscanneractivity(18814): mkdirs() 09-10 16:00:59.504: e/nfcscanneractivity(18814): fos 09-10 16:00:59.644: e/mp-decision(2194): update arg 1 09-10 16:01:00.674: e/nfcscanneractivity(18814): update error = java.io.filenotfoundexception: http://cfweb.yourofficeanywhere.co.uk/entryactivityv33.apk 09-10 16:01:00.674: e/nfcscanneractivity(18814): @ com.android.okhttp.internal.http.httpurlconnectionimpl.getinputstream(httpurlconnectionimpl.java:186) 09-10 16:01:00.674: e/nfcscanneractivity(18814): @ com.carefreegroup.rr3.nfcscanneractivity.updateapp(nfcscanneractivity.java:6353) 09-10 16:01:00.674: e/nfcscanneractivity(18814): @ com.carefreegroup.rr3.nfcscanneractivity$asyncupdateapp.doinbackground(nfcscanneractivity.java:6317) 09-10 16:01:00.674: e/nfcscanneractivity(18814): @ com.carefreegroup.rr3.nfcscanneractivity$asyncupdateapp.doinbackground(nfcscanneractivity.java:1) 09-10 16:01:00.674: e/nfcscanneractivity(18814): @ android.os.asynctask$2.call(asynctask.java:288) 09-10 16:01:00.674: e/nfcscanneractivity(18814): @ java.util.concurrent.futuretask.run(futuretask.java:237) 09-10 16:01:00.674: e/nfcscanneractivity(18814): @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1112) 09-10 16:01:00.674: e/nfcscanneractivity(18814): @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:587) 09-10 16:01:00.674: e/nfcscanneractivity(18814): @ java.lang.thread.run(thread.java:811)
Comments
Post a Comment