public static File downLoad (String serverpath,string savedpath,progressdialog Dialog) {try {URL url=new url (serverpath); HttpURLConnection _conn= (httpurlconnection) url.openconnection (); _conn.setrequestmethod ("GET"); _ Conn.setconnecttimeout (), int code=_conn.getresponsecode (), if (code==200) {//Set the length of the progress bar Dialog.setmax (_ Conn.getcontentlength ()); InputStream Is=_conn.getinputstream (); File _file=new file (Savedpath); FileOutputStream _fileoutputstream=new FileOutputStream (_file); int len=0;byte[] buffer= new Byte[1024];int _total=0; while ((Len=is.read (buffer))!=-1) {_fileoutputstream.write (buffer, 0,len); _total+=len;dialog.setprogress (_total); Thread.Sleep (20);} _fileoutputstream.flush (); _fileoutputstream.close (); Is.close (); return _file;} else {return null;}} catch (Exception e) {//TODO auto-generated catch Blocke.printstacktrace (); return null;}}
Android Connection Server download file tool class