Read the Contents of a Zip File Using the Package

Read the Contents of a Zip File Using the Package

This example code extracts the content of a zip file (the name of the zip file is supplied in args[0]). First, open the zip file using ZipFile class, then loop through all entries in the zip file and extract the content. If one entry is a directory then create it.

 import*;import java.util.*;import*;public class ReadZipFile{	public static void main(String args[]) throws Exception{//first argumentis zip file name		if(args.length==0){			System.out.println("Zip file name is missing");			return;		}		ZipEntry ze;		byte buf[];		FileOutputStream fout;		File dir;		ZipFile zf=new ZipFile(args[0]);		Enumeration zentries=zf.entries();		while(zentries.hasMoreElements()){			ze=(ZipEntry)zentries.nextElement();			System.out.println(ze.getName());			if(!ze.isDirectory()){				buf=new byte[(int)ze.getSize()];	//create buffer to store data				zf.getInputStream(ze).read(buf);	//read data from file in zip file				fout=new FileOutputStream(ze.getName());				fout.write(buf);	//write data to file				fout.close();			}else{				dir=new File(ze.getName());	//create directory				dir.mkdir();			}		}		zf.close();	}}
Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of