How to zip and unzip png images in android -


hi in app when click zip button need zip image file , and when click unzip button need unzip file,i tried using below code zip image problem when click zip button zip file creating,but after in system using winzip software try open file not opening showing "it not appear valid archive valid file" did mistake can u let me how zip , unzip images

public class mainactivity extends activity { /** called when activity first created. */

button zip,unzip;    string []s=new string[2];    @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.main);        zip=(button)findviewbyid(r.id.button1);     zip.setonclicklistener(new onclicklistener() {          public void onclick(view arg0) {             // todo auto-generated method stub             s[0]="/sdcard/saved_images/main.png";                 //s[1]="/sdcard/physics_lab/stefans_law/stefan_law.txt"; // path of second file             compress c =new compress(s,"/sdcard/saved_images/stefen.zip");                c.zip();             }     });      }   }     public class compress {        private static final int buffer = 80000;         private string[] _files;          private string _zipfile;      public compress(string[] files, string zipfile) {          _files = files;       _zipfile = zipfile;       }      public void zip() {      try  {       bufferedinputstream origin = null;           fileoutputstream dest = new fileoutputstream(_zipfile);           zipoutputstream out = new zipoutputstream(new bufferedoutputstream(dest));     byte data[] = new byte[buffer];     for(int i=0; < _files.length; i++) {        log.d("add:",_files[i]);     log.v("compress", "adding: " + _files[i]);      fileinputstream fi = new fileinputstream(_files[i]);      origin = new bufferedinputstream(fi, buffer);      zipentry entry = new zipentry(_files[i].substring(_files[i].lastindexof("/") + 1));      out.putnextentry(entry);      int count;      while ((count = origin.read(data, 0, buffer)) != -1) {        out.write(data, 0, count);      }      origin.close();    }     out.close();  } catch(exception e) {    e.printstacktrace();  }      }        }  

you can check out these 2 tutorials zip , unzip file

android zip file

android unzip file


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

java - Using an Integer ArrayList in Android -