How to Get Uncompressed Size of Zip Entry in Java


In this example we will show the common method to get uncompressed size of zip entry (i.e. file or directory).

Source Code

package com.beginner.examples;

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

 
public class UncompressedSizeExample {
	
	public static void main(String args[])
	{		 
		try
		{
		    //open a zip file
			ZipFile zipFile = new ZipFile("D:/Workspaces/test.zip");
		   
		    Enumeration en = zipFile.entries();
			
			while(en.hasMoreElements())
			{
				ZipEntry zip = (ZipEntry)en.nextElement();
				//get name of an entry
				String name = zip.getName();
				
				long size = zip.getSize();
				 
				System.out.println(name);
				System.out.println("originalSize : " + size);
							
			}
	 	 
			zipFile.close();
		 	
		 }
		 catch(IOException e)
		 {
			 e.printStackTrace();
		 }
	}
 
}

Output:

test.txt
originalSize : 3

References

Imported packages in Java documentation:

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments