Skip to Content

Get Zip Entry Example

  • strict warning: Non-static method view::load() should not be called statically in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/views.module on line 906.
  • strict warning: Declaration of views_handler_argument::init() should be compatible with views_handler::init(&$view, $options) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_argument.inc on line 0.
  • strict warning: Declaration of views_handler_filter::options_validate() should be compatible with views_handler::options_validate($form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_filter.inc on line 0.
  • strict warning: Declaration of views_handler_filter::options_submit() should be compatible with views_handler::options_submit($form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_filter.inc on line 0.
  • strict warning: Declaration of views_handler_filter_boolean_operator::value_validate() should be compatible with views_handler_filter::value_validate($form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_filter_boolean_operator.inc on line 0.
  • strict warning: Declaration of views_plugin_style_default::options() should be compatible with views_object::options() in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/plugins/views_plugin_style_default.inc on line 0.
  • strict warning: Declaration of views_plugin_row::options_validate() should be compatible with views_plugin::options_validate(&$form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/plugins/views_plugin_row.inc on line 0.
  • strict warning: Declaration of views_plugin_row::options_submit() should be compatible with views_plugin::options_submit(&$form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/plugins/views_plugin_row.inc on line 0.

  1. /*
  2.         Get Zip Entry Example
  3.         This Java example shows how to get comment for specified
  4.         zip entry or all zip entries using getComment method of Java
  5.         ZipEntry class.
  6. */
  7.  
  8. import java.io.File;
  9. import java.io.IOException;
  10. import java.util.Enumeration;
  11. import java.util.zip.ZipEntry;
  12. import java.util.zip.ZipFile;
  13.  
  14. public class GetComment {
  15.        
  16.         public static void main(String args[])
  17.         {                
  18.                 try
  19.                 {
  20.                    /*
  21.                         * To Open a zip file, use
  22.                         *
  23.                         * ZipFile(String fileName)
  24.                         * constructor of the ZipFile class.
  25.                         *
  26.                         * This constructor throws IOException for any I/O error.
  27.                         */
  28.                    ZipFile zipFile = new ZipFile("c:/FileIO/WebFiles.zip");
  29.                    
  30.                    /*
  31.                     * Get list of zip entries using entries method of
  32.                     * ZipFile class.
  33.                     */
  34.                    
  35.                         Enumeration e = zipFile.entries();
  36.                        
  37.                         while(e.hasMoreElements())
  38.                         {
  39.                                 ZipEntry entry = (ZipEntry)e.nextElement();
  40.                                                                
  41.                                 /*
  42.                                  * To get comment associated with zip entry or
  43.                                  * archived file, use
  44.                                  *
  45.                                  * String getComment() method of ZipEntry Class.
  46.                                  *
  47.                                  * This method returns null if no comment is specified
  48.                                  * for particular entry.
  49.                                  */
  50.                                  
  51.                                  String comment = entry.getComment();
  52.                                  
  53.                                  if("".equals(comment))
  54.                                         System.out.println(comment + " found for entry " + entry.getName());
  55.                                  else
  56.                                         System.out.println("No comments found for entry " + entry.getName());
  57.                         }
  58.                  
  59.                          /*
  60.                           * close the opened zip file using,
  61.                           * void close()
  62.                           * method.
  63.                           */
  64.                          
  65.                           zipFile.close();
  66.                        
  67.                  }
  68.                  catch(IOException ioe)
  69.                  {
  70.                         System.out.println("Error opening zip file" + ioe);
  71.                  }
  72.         }
  73. }
  74.  
  75. /*
  76. Output of this program would be,
  77. No comments found for entry css/datagrid.css
  78. No comments found for entry css/graph.css
  79. No comments found for entry css/icons.css
  80. No comments found for entry jsps/Masthead.jspf
  81. No comments found for entry jsps/Welcome.jsp
  82.  
  83. */