//// // The file download function is as follows/ //// // Private void downfile (string urlstring) {/** connect to the server */Double filelength = 0; double downedfilelength = 0; inputstream = NULL; urlconnection connection = NULL; outputstream = NULL; try {URL url = new URL (urlstring); connection = URL. openconnection (); If (connection. getreadtimeout () = 5) {log. I ("----------> "," The current network has a problem ");} inputstream = connection. getinputstream ();} catch (malformedurlexception E1) {// todo auto-generated catch blocke1.printstacktrace ();} catch (ioexception e) {// todo auto-generated catch blocke. printstacktrace ();}/** specifies the path of the file to be saved on the SD card of the mobile phone. If not, create */string savepath = environment. getexternalstoragedirectory () + "/lzmdownload"; file file1 = new file (savepath); If (! File1.exists () {file1.mkdir ();} string savepathstring = environment. getexternalstoragedirectory () + "/lzmdownload/" + "test.png"; file = new file (savepathstring); try {L. L ("=================================== newfile:" + file. createnewfile (); file. createnewfile (); L. L ("=================================== newfile:" + file. createnewfile ();} catch (ioexception e) {// todo auto-generated catch blocke. printstacktrace ();}/** write a file to the SD card and use the handle transmission thread */message = new message (); try {outputstream = new fileoutputstream (File ); byte [] buffer = new byte [1024*4]; filelength = connection. getcontentlength (); L. L ("========================== filesize:" + filelength); message. what = 0; handler. sendmessage (Message); While (downedfilelength <filelength) {outputstream. write (buffer); downedfilelength + = inputstream. read (buffer); I = (INT) (double) downedfilelength/filelength) * 100); message message1 = new message (); message1.what = 1; // downloading... the filehandler. sendmessage (message1);} message message2 = new message (); // finish the downloadmessage2.what = 2; handler. sendmessage (message2);} catch (filenotfoundexception e) {// todo auto-generated catch blocke. printstacktrace ();} catch (ioexception e) {// todo auto-generated catch blocke. printstacktrace ();}} /// // The above is a download class ////////////// ///////////////////////////////