The code snippet below explains how to extract zip file in android
You can call extractZip method with activity from where its called and path of file to be extracted
It will extract the files on same destination path
/**
* This method will extract the zip file from location inside application
*
* @param activity
* @param destinationPath - Path of zip file
* @param _location - location where file will be extracted
* @author Yash@iotasol.com
*/
public void extractZip(Activity activity,String destinationPath,String _location ) {
System.out.println(" ctr : ::: extract zip" + zipExtracted + " : "
+ destinationPath);
FileInputStream fin = null;
ZipInputStream zin = null;
try {
fin = new FileInputStream(destinationPath);
zin = new ZipInputStream(fin);
ZipEntry ze = null;
while ((ze = zin.getNextEntry()) != null) {
if (ze.isDirectory()) {
extractDirectoryZipEntry(ze.getName(), _location);
} else {
extractZipFileEntry(_location, zin, ze);
}
}
zipExtracted = true;
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (zin != null) {
zin.close();
}
if (fin != null) {
fin.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* This method will work on every single zip entry and store it in location
* Buffered input stream is used to speed up the downloading process
* @param _location
* @param zin
* @param ze
* @author Yash@iotasol.com
*/
private void extractZipFileEntry(String _location, ZipInputStream zin,
ZipEntry ze) {
System.out.println(">>>>> file : " + ze.getName());
FileOutputStream fout = null;
BufferedOutputStream bout = null;
try {
fout = new FileOutputStream(_location + ze.getName());
bout = new BufferedOutputStream(fout, 1024);
byte[] data = new byte[1024];
int x = 0;
while ((x = zin.read(data, 0, 1024)) >= 0) {
bout.write(data, 0, x);
}
} catch (Exception r) {
r.printStackTrace();
} finally {
try {
zin.closeEntry();
if (bout != null)
bout.close();
if (fout != null)
fout.close();
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println(">>>>> file downloaded: " + ze.getName());
}
/**
* This method will work on every single zip entry in case if its a directory, and creates new
*
* @param dir
* @param _location
* @author Yash@iotasol.com
*/
private void extractDirectoryZipEntry(String dir, String _location) {
File f = new File(_location + dir);
if (!f.isDirectory()) {
f.mkdirs();
}
}
I hope this post will be helpful.
Please share your comments and and you can also contact me @ yash@iotasol.com or visit our site www.iotasol.com , www.iotadomains.com.
i m ur first follower after u ...:P
ReplyDelete@Arsh: Thanks for your comment.
ReplyDeleteawesome solution.........really helped me......was stuck on this for quite some time....
ReplyDeleteThanks Iotasol. You Rock :)
This comment has been removed by a blog administrator.
ReplyDeleteIt Rocks Mate,Simplest Steps with simplest coding,Looking forward for more of them
ReplyDeleteThanks for this post.. It helped me... Whats is ur twitter account?
ReplyDeleteThanks varun, my twitter is @ceryash and @iotasol
ReplyDeleteAfter reading your post I understood that last week was with full of surprises and happiness for you. Congratz! Even though the website is work related, you can update small events in your life and share your happiness with us too.
ReplyDeleteData Science with Python training in chenni
Data Science training in chennai
Data science training in velachery
Data science training in tambaram
Data Science training in anna nagar
Data Science training in chennai
Data science training in Bangalore
This is a good post. This post give truly quality information. I’m definitely going to look into it. Really very useful tips are provided here. thank you so much. Keep up the good works.
ReplyDeletepython online training
python training in OMR
python training in tambaram
Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.
ReplyDeleteDevops training in velachery
Devops training in annanagar
Devops training in tambaram
DevOps online Training
I’ve desired to post about something similar to this on one of my blogs and this has given me an idea. Cool Mat.
ReplyDeleteBlueprism online training
Blue Prism Training in Pune
Well researched article and I appreciate this. The blog is subscribed and will see new topics soon.
ReplyDeleteangularjs Training in bangalore
angularjs Training in bangalore
angularjs Training in btm
angularjs Training in electronic-city
angularjs online Training
Hey, Wow all the posts are very informative for the people who visit this site. Good work! We also have a Website. Please feel free to visit our site. Thank you for sharing.Well written article Thank You Sharing with Us pmp training Chennai | pmp training centers in Chennai | pmp training institutes in Chennai | pmp training and certification in Chennai | pmp training in velachery
ReplyDeleteHi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging.
ReplyDeleteMicrosoft Azure online training
Selenium online training
Java online training
Python online training
uipath online training
Your info is really amazing with impressive content..Excellent blog with informative concept. Really I feel happy to see this useful blog, Thanks for sharing such a nice blog..
ReplyDeleteIf you are looking for any Data science Related information please visit our website best course for data science page!
Good post..
ReplyDeleteinplant training in chennai
inplant training in chennai
inplant training in chennai for it.php
Australia hosting
mexico web hosting
moldova web hosting
albania web hosting
andorra hosting
australia web hosting
denmark web hosting
mmorpg
ReplyDeleteINSTAGRAM TAKİPCİ SATİN AL
tiktok jeton hilesi
tiktok jeton hilesi
antalya saç ekimi
referans kimliği nedir
instagram takipçi satın al
metin2 pvp serverlar
instagram takipçi
en son çıkan perde modelleri
ReplyDeletesms onay
mobil ödeme bozdurma
nft nasıl alınır
ANKARA EVDEN EVE NAKLİYAT
TRAFİK SİGORTASI
dedektör
HTTPS://KURMA.WEBSİTE/
aşk kitapları