V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
superhan
V2EX  ›  Python

求帮忙,使用 Python 解压 Java 压缩的 zip 文件问题

  •  
  •   superhan · 2017-11-14 14:13:12 +08:00 · 2259 次点击
    这是一个创建于 2347 天前的主题,其中的信息可能已经有所发展或是发生改变。

    java zip 压缩部分是这样到:

    byteArrayOutputStream = new ByteArrayOutputStream(); zipOutputStream = new ZipOutputStream(byteArrayOutputStream); zipOutputStream.putNextEntry(new ZipEntry("0")); zipOutputStream.write(paramString.getBytes()); zipOutputStream.closeEntry(); arrayOfByte = byteArrayOutputStream.toByteArray();

    python 使用 zipfile 时会报错,识别不出这是一个 zip 文件。请高手指点一下!!

    第 1 条附言  ·  2017-11-15 16:37:14 +08:00
    是因为 java 代码中, 没有关闭 zipOutputStream 就返回了压缩的数据流,导致 zip 不完整。
    4 条回复    2017-11-15 16:36:00 +08:00
    superhan
        1
    superhan  
    OP
       2017-11-14 14:26:22 +08:00
    java python 高手帮忙看看
    lieh222
        2
    lieh222  
       2017-11-15 15:50:28 +08:00   ❤️ 1
    这是 zip 文件还是 zlib 压缩的数据流呀。。
    superhan
        3
    superhan  
    OP
       2017-11-15 15:54:51 +08:00
    @lieh222 你好,是压缩到数据流,我把数据流保存成为文件,但是解压还是失败,好像是缺少一些尾部信息。
    superhan
        4
    superhan  
    OP
       2017-11-15 16:36:00 +08:00
    @lieh222 你好 找到原因了谢谢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5218 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 82ms · UTC 01:24 · PVG 09:24 · LAX 18:24 · JFK 21:24
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.