skip to main | skip to sidebar

Java Programs and Examples with Output

Pages

▼
 
  • RSS
  • Twitter
Monday, September 10, 2012

Get All Entries From Zip File Example

Posted by Admin at 1:34 PM – 0 comments
 
Get All Entries From Zip File Example.
This Java example shows how to get enumeration of all entries
(i.e. files or directories) using entries method of
Java ZipFile class.

     
    import java.io.IOException;
    import java.util.Enumeration;
    import java.util.zip.ZipEntry;
    import java.util.zip.ZipFile;
     
    public class GetAllEntries {
           
            public static void main(String args[])
            {
                     try
                     {
                            /*
                             * Open zip file using,
                             *
                             * 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");
     
                            /*
                             * To get all entries from opened zip file, use
                             *
                             * Enumeration entries()
                             * method of ZipFile class.
                             *
                             * This method returns Enumeration of zip file entries.
                             */
                           
                            Enumeration e = zipFile.entries()                     
                            /*
                             * close the opened zip file using,
                             * void close()
                             * method.
                             */
                             
                             zipFile.close();
           
                     }
                     catch(IOException ioe)
                     {
                            System.out.println("Error opening zip file" + ioe);
                     }
            }
    }



Labels: Zip File

Leave a Reply

Newer Post Older Post
Subscribe to: Post Comments ( Atom )
  • Popular
  • Recent
  • Archives
Powered by Blogger.
 
 
 
© 2011 Java Programs and Examples with Output | Designs by Web2feel & Fab Themes

Bloggerized by DheTemplate.com - Main Blogger