How to download a file from the web using Android 1.6 -
i trying download zipped file web on first instance of application; can point me tutorial (i don't see documentation on developer.android)? understand how check if it's initial start or not, , how use java.util.zip once file, it's in-between i'm lost.
i think question how download file. so, download file, use code similar following:
url u = new url("http://www.example.com/downloadfile.zip"); httpurlconnection c = (httpurlconnection) u.openconnection(); c.setrequestmethod("get"); c.setdooutput(true); c.connect(); fileoutputstream fnew = new fileoutputstream(new file(root,"downloadfile.zip")); inputstream instream = c.getinputstream(); byte[] buffer = new byte[1024]; int inlen = 0; while ( (inlen = instream.read(buffer)) > 0 ) { fnew.write(buffer,0, inlen); } fnew.close(); instream.close();
of course, wrap appropriate error checking
Comments
Post a Comment