Saturday, January 02, 2010

Reading a zip file

This sample code read the name of all files from a zip file. It uses ZipInputStream to read zip file.


import java.io.*;
import java.util.zip.*;

public class ZipFileRdrExp {

public static void main(String[] args) {

try {

FileInputStream fis = new FileInputStream("C:\\MyZip.zip");
ZipInputStream zis = new ZipInputStream(fis);
ZipEntry ze;
while((ze=zis.getNextEntry())!=null){
System.out.println(ze.getName());
zis.closeEntry();
}

zis.close();

} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}


Source: java-tips.org

No comments:

Computers Add to Technorati Favorites Programming Blogs - BlogCatalog Blog Directory