Here you can find the source of getFilesCount(File archiveFile)
Parameter | Description |
---|---|
archiveFile | the zip file |
Parameter | Description |
---|---|
IOException | an exception |
public static int getFilesCount(File archiveFile) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2016 ARM Ltd. and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:// www. j av a 2 s.c om * ARM Ltd and ARM Germany GmbH - Initial API and implementation *******************************************************************************/ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; public class Main { /** * @param archiveFile the zip file * @return the number of files contained in this zip file * @throws IOException */ public static int getFilesCount(File archiveFile) throws IOException { ZipInputStream zipInput; zipInput = new ZipInputStream(new FileInputStream(archiveFile)); ZipEntry zipEntry = zipInput.getNextEntry(); int count = 0; while (zipEntry != null) { if (!zipEntry.isDirectory()) { count++; } zipEntry = zipInput.getNextEntry(); } zipInput.closeEntry(); zipInput.close(); return count; } }