Reputation: 289
I am trying to list files in a zip folder. I understand i can use the zip4j library or the java ZipFile
class.
My question is using either of these tools, how can I list files in a given directory within the zip?
Upvotes: 0
Views: 780
Reputation: 2961
It is possible to solve the task with just ZipInputStream.
final String folderNameToBrowse = "folder_name";
final String archivePath = "archive.zip";
final Path pathToBrowse = Paths.get(folderNameToBrowse);
ZipInputStream zis = new ZipInputStream(new FileInputStream(archivePath));
ZipEntry temp = null;
while ( (temp = zis.getNextEntry()) != null) {
if(!temp.isDirectory()){
Path currentPath = Paths.get(temp.getName());
if(pathToBrowse.equals(currentPath.getParent())){
// Here is the file name
System.out.println(currentPath.getFileName());
}
}
}
Upvotes: 1