1
votes

we can extract all the files from a zoip filder using extractAll method given in zip4j, but what if i need to extract only one kind of files,say only text files or only files which have a certain sub-string in the name of the file?? is there a way to do this using zip4j

i thought this question might be relating to my problem

Read Content from Files which are inside Zip file

but that's not exactly what i want. can anyone explain in detail about using this ZipEntry things, if it helps my problem getting solved?

1
did you check the lingala.net/zip4j website first? Does their forum answer this question? - Mike 'Pomax' Kamermans
i see this point mentioned on the forum "Create or extract files from Split Zip files (Ex: z01, z02,...zip)" but it does not say if you can extract files based on the type of file or by specifying a substring in the file name inside the zip folder - Vasanth Nag K V

1 Answers

2
votes

Try the below code

        ZipFile zipFile = new ZipFile("myzip.zip");

        // Get the list of file headers from the zip file
        List fileHeaderList = zipFile.getFileHeaders();

        // Loop through the file headers
        for (int i = 0; i < fileHeaderList.size(); i++) {
            FileHeader fileHeader = (FileHeader)fileHeaderList.get(i);              
            String fileName = fileHeader.getFileName();
            if(fileName.contains(".java")){
                zipFile.extractFile(fileHeader, "c:\\scrap\\");
            }

        }