Intro
This examples, will demonstrates how to get number of files in zip file. To get total number of files, you can use ZipFile.size() method.
Examples
package com.freesamplecode.java.zip;
import java.io.IOException;
import java.util.zip.ZipFile;
public class GetNumberOfFilesDemo {
public static void main(String[] args){
ZipFile zipFile = null;
try {
zipFile = new ZipFile("D:/temp/data.zip");
int numberOfFiles = zipFile.size();
System.out.println("Number of files in zip file "+zipFile.getName() + " are : "+numberOfFiles + " files");
zipFile.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Output
Number of files in zip file D:\temp\data.zip are : 6 files

0 comments: