In this example we are going to see How to Read Entries In Zip File In Java Example.
Java Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | import java.io.File; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Enumeration; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; public class JavaReadEntriesZip { public static void main(String[] args) throws Exception { ZipFile zip = new ZipFile(new File("sample.zip")); for (Enumeration e = zip.entries(); e.hasMoreElements();) { ZipEntry entry = (ZipEntry) e.nextElement(); System.out.println("File name: " + entry.getName() + "; size: " + entry.getSize() + "; compressed size: " + entry.getCompressedSize()); InputStream is = zip.getInputStream(entry); InputStreamReader isr = new InputStreamReader(is); char[] buffer = new char[1024]; while (isr.read(buffer, 0, buffer.length) != -1) { String s = new String(buffer); System.out.println(s.trim()); } } } } |
Read Entries In A Zip File, Java