There are many articles on the Internet to download files or extract zip files, but the combination of the few, here to record the download zip file and directly unzip the method.
In fact, it is also very simple, is to download files and unzip the zip file together. Here is the code:
URLConnection Connection; Zipinputstream Zipin=NULL; FileOutputStream Fileout=NULL; ZipEntry ZipEntry=NULL; intReadedbytes = 0; Try{Connection=modelurl.openconnection (); LOG.V (TAG,"Model file Length:" +connection.getcontentlength ()); Zipin=NewZipinputstream (Connection.getinputstream ()); while((ZipEntry = Zipin.getnextentry ())! =NULL) {String entryName=Zipentry.getname (); if(Zipentry.isdirectory ()) {EntryName= entryname.substring (0, Entryname.length ()-1); File folder=NewFile (FolderPath + file.separator+entryName); Folder.mkdirs (); } Else{String FileName=folderpath + File.separator +EntryName; File File=NewFile (fileName); File.createnewfile (); Fileout=Newfileoutputstream (file); while((Readedbytes = Zipin.read (downloadbuffer)) > 0) {fileout.write (Downloadbuffer,0, readedbytes); Total+=readedbytes; } fileout.close (); } zipin.closeentry (); } zipin.close (); } Catch(IOException e) {e.printstacktrace (); }
Android Download zip archive and unzip