Removing a jar files META-INF folder in Java

2019-07-20 16:09发布

问题:

I am using the following method to filter out META-INF folder and its contents:

public static void copyWithoutMetaInf(final String originalZip, final String newZip) throws IOException
{
    final ZipInputStream zip = new ZipInputStream(new FileInputStream(originalZip));
    final ZipOutputStream zop = new ZipOutputStream(new FileOutputStream(newZip));
    ZipEntry entry;
    while((entry = zip.getNextEntry()) != null)
    {
        if(!entry.getName().contains("META-INF"))
        {
            zop.putNextEntry(entry);
        }
    }
    zip.close();
    zop.close();
}

Method found here: https://stackoverflow.com/a/22433569/3952266

The only problem is that when it creates the new file it only outputs a file a tenth of the original size.