Tuesday, October 9, 2012

Get contents of a ZIP file in Java, how to get file names in zip file in java

import java.io.File;
import java.io.IOException;
import java.util.Enumeration;
import java.util.zip.ZipFile;

public class ZipContents {
public static void main(String[] args) {
File zipFileName = new File("src\\myZip.zip");
getContentsInZip(zipFileName);
}

public static void getContentsInZip(File zipFileName){
try{ ZipFile zipFile = new ZipFile(zipFileName);
Enumeration em = zipFile.entries();
for (Enumeration enumer = zipFile.entries(); enumer.hasMoreElements();) {
System.out.println(enumer.nextElement());
}
}catch(IOException e){ e.printStackTrace(); }
}
}

0 comments:

Post a Comment