Extracting SFX 7-Zip

纵饮孤独 提交于 2019-12-12 01:46:00

问题


I want to extract two specific files from a .zip file. I tried the following library:

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

Result:

Exception in thread "main" java.util.zip.ZipException: error in opening zip file

I also tried:

public void extract(String targetFileName) throws IOException
{
    OutputStream outputStream = new FileOutputStream("targetFile.foo");
    FileInputStream fileInputStream = new FileInputStream("myZip.zip");
    ZipInputStream zipInputStream = new ZipInputStream(new BufferedInputStream(fileInputStream));
    ZipEntry zipEntry;

    while ((zipEntry = zipInputStream.getNextEntry()) != null)
    {
        if (zipEntry.getName().equals("targetFile.foo"))
        {
            byte[] buffer = new byte[8192];
            int length;
            while ((length = zipInputStream.read(buffer)) != -1)
            {
                outputStream.write(buffer, 0, length);
            }
            outputStream.close();
            break;
        }
    }
}

Result:
No exception, but an empty targetFile.foo file.

Note that the .zip file is of type SFX 7-zip and initially had the .exe extensions so that may be the reason for the failure.

来源:https://stackoverflow.com/questions/35670707/extracting-sfx-7-zip

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