Mega Code Archive

 
Categories / Java / File Input Output
 

Validate that an archive contains a named entry

import java.io.File; import java.io.IOException; import java.util.Enumeration; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; public class Utils {   /**    * Validate that an archive contains a named entry    *     * @param theFile    * @param name    * @return true if the entry exists    * @throws IOException    */   public static boolean archiveContainsEntry(File theFile, String name) throws IOException {       boolean result = false;       ZipFile zipFile;       zipFile = new ZipFile(theFile);       for (Enumeration entries = zipFile.entries(); entries.hasMoreElements();) {           ZipEntry entry = (ZipEntry) entries.nextElement();           if (entry.getName().equals(name)) {               result = true;               break;           }       }       zipFile.close();       return result;   } }