Over 500 Magazines for FREE!

Yes! You can subscribe to ALL of them. They will be shipped to your home FREE of cost!
Kindly click here to apply!

Determine if the Zip Entry Is Directory Example

  1. /*
  2. Determine if the Zip Entry Is Directory Example
  3. This Java example shows how to determine if the entry is directory
  4. of a file using isDirectory method of Java ZipEntry class.
  5. */
  6.  
  7. import java.io.IOException;
  8. import java.util.Enumeration;
  9. import java.util.zip.ZipEntry;
  10. import java.util.zip.ZipFile;
  11.  
  12.  
  13. public class DetermineDirectory {
  14.  
  15. public static void main(String args[])
  16. {
  17. try
  18. {
  19. /*
  20. * To Open a zip file, use
  21. *
  22. * ZipFile(String fileName)
  23. * constructor of the ZipFile class.
  24. *
  25. * This constructor throws IOException for any I/O error.
  26. */
  27. ZipFile zipFile = new ZipFile("c:/FileIO/WebFiles.zip");
  28.  
  29. /*
  30. * Get list of zip entries using entries method of
  31. * ZipFile class.
  32. */
  33.  
  34. Enumeration e = zipFile.entries();
  35.  
  36. System.out.print("File Name");
  37. System.out.print("\t\t\t\tIs Directory");
  38. System.out.print("\n---------------------------------\n");
  39.  
  40. while(e.hasMoreElements())
  41. {
  42. ZipEntry entry = (ZipEntry)e.nextElement();
  43.  
  44. /*
  45. * To determine if the entry is a directory, use
  46. *
  47. * boolean isDirectory()
  48. * method of Java ZipEntry class.
  49. *
  50. * This method returns true is the entry is directory,
  51. * false otherwise.
  52. *
  53. * Typically, directory entry is the one which contains
  54. * "/" at the end.
  55. */
  56.  
  57. String entryName = entry.getName();
  58. boolean isDir = entry.isDirectory();
  59.  
  60. System.out.print(entryName);
  61. System.out.print("\t\t\t\t" + isDir);
  62. System.out.print("\n");
  63.  
  64. }
  65.  
  66. /*
  67. * close the opened zip file using,
  68. * void close()
  69. * method.
  70. */
  71.  
  72. zipFile.close();
  73.  
  74. }
  75. catch(IOException ioe)
  76. {
  77. System.out.println("Error opening zip file" + ioe);
  78. }
  79. }
  80.  
  81. }
  82.  
  83. /*
  84. Output of this program would be
  85. File Name Is Directory
  86. ---------------------------------
  87. css/datagrid.css false
  88. css/graph.css false
  89. jsps/Masthead.jspf false
  90. jsps/Welcome.jsp false
  91. */

Post new comment

To combat spam, please enter the code in the image.




Do you have a better example?
We're sure you have hundreds of Java program examples.

Spare some time and submit your java example here even if you think it's too small to contribute.

Could not find what you are looking for? Search Java Examples




Feel Tired? Read Jokes & Inspirational Stories, Play Games!