/*
Determine if the Zip Entry Is Directory Example
This Java example shows how to determine if the entry is directory
of a file using isDirectory method of Java ZipEntry class.
*/
import java.io.IOException;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
public class DetermineDirectory {
public static void main(String args[])
{
try
{
/*
* To Open a zip file, use
*
* 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");
/*
* Get list of zip entries using entries method of
* ZipFile class.
*/
Enumeration e = zipFile.entries();
System.out.print("File Name");
System.out.print("\t\t\t\tIs Directory");
System.out.print("\n---------------------------------\n");
while(e.hasMoreElements())
{
ZipEntry entry = (ZipEntry)e.nextElement();
/*
* To determine if the entry is a directory, use
*
* boolean isDirectory()
* method of Java ZipEntry class.
*
* This method returns true is the entry is directory,
* false otherwise.
*
* Typically, directory entry is the one which contains
* "/" at the end.
*/
String entryName = entry.getName();
boolean isDir = entry.isDirectory();
System.out.print(entryName);
System.out.print("\t\t\t\t" + isDir);
System.out.print("\n");
}
/*
* close the opened zip file using,
* void close()
* method.
*/
zipFile.close();
}
catch(IOException ioe)
{
System.out.println("Error opening zip file" + ioe);
}
}
}
/*
Output of this program would be
File Name Is Directory
---------------------------------
css/datagrid.css false
css/graph.css false
jsps/Masthead.jspf false
jsps/Welcome.jsp false
*/