Removing a jar files META-INF folder in Java

家住魔仙堡 提交于 2020-02-04 14:41:02

问题


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.

来源:https://stackoverflow.com/questions/30859295/removing-a-jar-files-meta-inf-folder-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!