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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
/* Get Compressed Size of Zip Entry Example This Java example shows how to get compressed size of particular entry (i.e. file or directory) using getCompressedSize method of Java ZipEntry class. */ import java.io.File; import java.io.IOException; import java.util.Enumeration; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; public class GetCompressedSize { public static void main(String args[]) { try { /* * To Open a zip file, use * * ZipFile(String fileName) * constructor of the ZipFile class. * * This constructor throws IOException for any I/O error. */ ZipFile zipFile = new ZipFile("c:/FileIO/WebFiles.zip"); /* * Get list of zip entries using entries method of * ZipFile class. */ Enumeration e = zipFile.entries(); System.out.print("File Name"); System.out.print("ttttCompressed Size"); System.out.println("---------------------------------"); while(e.hasMoreElements()) { ZipEntry entry = (ZipEntry)e.nextElement(); /* * To get compressed size of zip entry, use * * long getCompressedSize() * method of ZipEntry class. * * This method returns the size of compressed entry or -1 * if the size is not known. * * PLEASE NOTE that uncompressed size and compressed size * of the zip entries created using ZipEntry.STORED method * will be same. * * However, It differes for zip entries created using * ZipEntry.DEFLATED entries. */ String entryName = entry.getName(); long compressedSize = entry.getCompressedSize(); System.out.print(entryName); System.out.print("tttt" + compressedSize); System.out.print("n"); } /* * close the opened zip file using, * void close() * method. */ zipFile.close(); } catch(IOException ioe) { System.out.println("Error opening zip file" + ioe); } } } /* Output of this program would be File Name Compressed Size --------------------------------- css/datagrid.css 3255 css/graph.css 416 jsps/Masthead.jspf 536 jsps/Welcome.jsp 1248 */ |
Add Comment