Nuvola-inspired File Icons for MediaWiki-filei...

you can extract files form zip file using java
String LOCATION_ZIP_FILE = “C:\\Documents and Settings\\zeeshan\\Desktop\\ztestzip.zip”;
// declare helper constants
try {
String destinationname = “c:\\zip\\”;
byte[] buf = new byte[1024];
ZipInputStream zipinputstream = null;
ZipEntry zipentry;
File newFile = null;
zipinputstream = new ZipInputStream(
new FileInputStream(LOCATION_ZIP_FILE));

zipentry = zipinputstream.getNextEntry();
while (zipentry != null) {
//for each entry to be extracted
String entryName = destinationname + zipentry.getName();
entryName = entryName.replace(‘/’, File.separatorChar);
entryName = entryName.replace(‘\\’, File.separatorChar);
System.out.println(“entryname ” + entryName+”\n”+zipentry.getName());
int n;
FileOutputStream fileoutputstream;
newFile = new File(entryName);
if (zipentry.isDirectory()) {
if (!newFile.mkdirs()) {
break;
}
zipentry = zipinputstream.getNextEntry();
continue;
}

fileoutputstream = new FileOutputStream(entryName);

while ((n = zipinputstream.read(buf, 0, 1024)) > -1) {
fileoutputstream.write(buf, 0, n);

}

fileoutputstream.close();
zipinputstream.closeEntry();
zipentry = zipinputstream.getNextEntry();
newFile.delete();
}//while

zipinputstream.close();
} catch (Exception e) {
e.printStackTrace();
}

 

}

Advertisements
Comments
  1. Usman Ghani says:

    thanks Zeeshan

    Like

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s