Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
Java.util.zip.ZipInputStream class in Java
Next article icon

Java.util.zip.ZipEntry class in Java

Last Updated : 12 Sep, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

This class is used to represent a ZIP file entry.
Constructors

  • ZipEntry(String name) : Creates a new zip entry with the specified name.
  • ZipEntry(ZipEntry e) : Creates a new zip entry with fields taken from the specified zip entry.

Methods:

  • Object clone() : Returns a copy of this entry.
    Syntax :public Object clone()  Overrides:  clone in class Object  Returns:  a clone of this instance.
  • String getComment() : Returns the comment string for the entry, or null if none.
    Syntax :public String getComment()  Returns:  the comment string for the entry, or null if none
  • long getCompressedSize() : Returns the size of the compressed entry data, or -1 if not known.In the case of a stored entry, the compressed size will be the same as the uncompressed size of the entry.
    Syntax :public long getCompressedSize()  Returns:  the size of the compressed entry data, or -1 if not known
  • long getCrc() : Returns the CRC-32 checksum of the uncompressed entry data, or -1 if not known.
    Syntax :public long getCrc()  Returns:  the CRC-32 checksum of the uncompressed entry data, or -1 if not known
  • byte[] getExtra() : Returns the extra field data for the entry, or null if none.
    Syntax :=public byte[] getExtra()  Returns:  the extra field data for the entry, or null if none  
  • int getMethod() : Returns the compression method of the entry, or -1 if not specified.
    Syntax :public int getMethod()  Returns:  the compression method of the entry, or -1 if not specified
  • String getName() : Returns the name of the entry.
    Syntax :public String getName()  Returns:  the name of the entry  
  • long getSize() :Returns the uncompressed size of the entry data, or -1 if not known.
    Syntax :public long getSize()  Returns:  the uncompressed size of the entry data, or -1 if not know
  • long getTime() : Returns the modification time of the entry, or -1 if not specified.
    Syntax :public long getTime()  Returns:  the modification time of the entry, or -1 if not specified
  • int hashCode() : Returns the hash code value for this entry.
    Syntax :public int hashCode()  Overrides:  hashCode in class Object  Returns:  a hash code value for this object.
  • boolean isDirectory() : Returns true if this is a directory entry. A directory entry is defined to be one whose name ends with a ‘/’.
    Syntax :public boolean isDirectory()  Returns:  true if this is a directory entry
  • void setComment(String comment):Sets the optional comment string for the entry.ZIP entry comments have maximum length of 0xffff. If the length of the specified comment string is greater than 0xFFFF bytes after encoding, only the first 0xFFFF bytes are output to the ZIP file entry.
    Syntax :public void setComment(String comment)  Parameters:  comment - the comment string
  • void setCompressedSize(long csize) : Sets the size of the compressed entry data.
    Syntax :public void setCompressedSize(long csize)  Parameters:  csize - the compressed size to set to
  • void setCrc(long crc) : Sets the CRC-32 checksum of the uncompressed entry data.
    Syntax :public void setCrc(long crc)  Parameters:  crc - the CRC-32 value  Throws:  IllegalArgumentException
  • void setExtra(byte[] extra) : Sets the optional extra field data for the entry.
    Syntax :public void setExtra(byte[] extra)  Parameters:  extra - the extra field data bytes  Throws:  IllegalArgumentException
  • void setMethod(int method) : Sets the compression method for the entry.
    Syntax :public void setMethod(int method)  Parameters:  method - the compression method, either STORED or DEFLATED  Throws:  IllegalArgumentException 
  • void setSize(long size) : Sets the uncompressed size of the entry data.
    Syntax :public void setSize(long size)  Parameters:  size - the uncompressed size in bytes  Throws:  IllegalArgumentException 
  • void setTime(long time) : Sets the modification time of the entry.
    Syntax :public void setTime(long time)  Parameters:  time - the entry modification time in number of milliseconds since the epoch
  • String toString() : Returns a string representation of the ZIP entry.
    Syntax :public String toString()  Overrides:  toString in class Object  Returns:  a string representation of the object.

Program:




//Java program demonstrating ZipEntry methods
  
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.nio.file.attribute.FileTime;
import java.util.concurrent.TimeUnit;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
  
class ZipEntryDemo
{
    public static void main(String[] args) throws IOException
    {
        FileInputStream fis = new FileInputStream("Awesome CV.zip");
        ZipInputStream jis = new ZipInputStream(fis);
        PrintStream cout=System.out;
  
        //reading the next ZIP file entry
        ZipEntry ze = jis.getNextEntry();
  
        //illustrating getName()
        cout.println(ze.getName());
  
        //illustrating getComment()
        ze.setComment("This is a comment");
        cout.println(ze.getComment());
  
        //illustrating setCompressedSize() and getCompressedSize()
        ze.setCompressedSize(23l);
        cout.println("CompressedSize of the entry = " + ze.getCompressedSize());
  
        //illustrating getSize() and setSize()
        ze.setSize(53l);
        cout.println("Size = " + ze.getSize());
  
        //illustrating getCrc() and setCrc()
        ze.setCrc(01);
        cout.println(ze.getCrc());
  
        //illustrating getMethod and setMethod
        ze.setMethod(ZipEntry.STORED);
        cout.println(ze.getMethod());
  
        //illustrating getCreation and setCreation()
        ze.setCreationTime(FileTime.from(10000, TimeUnit.DAYS));
        cout.println(ze.getCreationTime());
  
        //illustrating getLastAccessTime and setLastAccessTime
        ze.setLastAccessTime(FileTime.from(1000,TimeUnit.DAYS));
        cout.println(ze.getLastAccessTime());
  
        //illustrating clone()
        ZipEntry zeclone = (ZipEntry) ze.clone();
        cout.println(zeclone.getName());
  
        //illustrating isDirectory
        cout.println(ze.isDirectory());
  
        //illustrating hashcode()
        cout.println("hashcode = " + ze.hashCode());
    }
}
 
 

Output :

awesome-cv.cls  This is a comment  CompressedSize of the entry = 23  Size = 53  1  0  1997-05-19T00:00:00Z  1972-09-27T00:00:00Z  awesome-cv.cls  false  hashcode = 1687382489  


Next Article
Java.util.zip.ZipInputStream class in Java

N

Nishant Sharma
Improve
Article Tags :
  • Java
Practice Tags :
  • Java

Similar Reads

  • Java.util.zip.ZipInputStream class in Java
    This class implements an input stream filter for reading files in the ZIP file format. Includes support for both compressed and uncompressed entries. Constructors: ZipInputStream(InputStream in) : Creates a new ZIP input stream. ZipInputStream(InputStream in, Charset charset) : Creates a new ZIP inp
    3 min read
  • Java.util.zip.ZipOutputStream class in Java
    This class implements an output stream filter for writing files in the ZIP file format. Includes support for both compressed and uncompressed entries. Constructor : ZipOutputStream(OutputStream out) : Creates a new ZIP output stream. ZipOutputStream(OutputStream out, Charset charset) : Creates a new
    3 min read
  • Java.lang.Runtime class in Java
    In Java, the Runtime class is used to interact with Every Java application that has a single instance of class Runtime that allows the application to interface with the environment in which the application is running. The current runtime can be obtained from the getRuntime() method. Methods of Java
    6 min read
  • Java.lang.Package Class in Java
    In Java, the package class was introduced in JDK 1.2 to encapsulate version data associated with a package. As the number of packages increases, knowing the version of the package has become important. This versioning information is retrieved and made available by the ClassLoader instance that loade
    9 min read
  • Java.util.zip.GZIPInputStream class in Java
    This class implements a stream filter for reading compressed data in the GZIP file format. Constructors GZIPInputStream(InputStream in) : Creates a new input stream with a default buffer size. GZIPInputStream(InputStream in, int size) : Creates a new input stream with the specified buffer size. Meth
    2 min read
  • java.nio.file.Paths Class in Java
    java.nio.file.Paths class contains static methods for converting path string or URI into Path. Class declaration : public final class Paths extends ObjectMethods: MethodDescriptionget(String first, String... more) This method converts a path string, or a sequence of strings that when joined form a p
    2 min read
  • java.nio.file.SimpleFileVisitor Class in Java
    The java.nio.file.SimpleFileVisitor Class is used to visit all the files in a directory and to re-throw I/O exceptions whenever an I/O error occurs. Class declaration : public class SimpleFileVisitor<T> extends Object implements FileVisitor<T>Constructor: protected SimpleFileVIsitor(): C
    3 min read
  • Java.Lang.Byte class in Java
    In Java, Byte class is a wrapper class for the primitive type byte which contains several methods to effectively deal with a byte value like converting it to a string representation, and vice-versa. An object of the Byte class can hold a single byte value. Constructors of Byte Class There are mainly
    6 min read
  • Java.util.zip.InflaterInputStream class in Java
    This class implements a stream filter for uncompressing data in the "deflate" compression format. It is also used as the basis for other decompression filters, such as GZIPInputStream. Constructors InflaterInputStream(InputStream in) : Creates a new input stream with a default decompressor and buffe
    3 min read
  • Java.util.zip.DeflaterInputStream class in Java
    Implements an input stream filter for compressing data in the "deflate" compression format. Constructor and Description DeflaterInputStream(InputStream in) : Creates a new input stream with a default compressor and buffer size. DeflaterInputStream(InputStream in, Deflater defl) : Creates a new input
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences