【问题标题】:PHP's gzuncompress function in Java?Java中PHP的gzuncompress函数?
【发布时间】:2009-08-13 10:47:53
【问题描述】:

我正在使用 PHP 的 gzcompress() 函数压缩字符串:

http://us2.php.net/manual/en/function.gzcompress.php

我想获取 PHP 压缩函数的输出并用 Java 解压缩字符串。任何人都可以让我走上正确的道路吗?

非常感谢!

【问题讨论】:

    标签: java php string gzip gzipinputstream


    【解决方案1】:

    看看GZIPInputStream:

    GZIPInputStream gzipInputStream = new GZIPInputStream(new FileInputStream(inFilename));
    byte[] buf = new byte[1024];
    int len;
    while ((len = gzipInputStream.read(buf)) > 0) {
        // buf contains uncompressed data      
    }
    

    【讨论】:

      【解决方案2】:

      这是非常古老的,但它可能只包含正确的信息来帮助您入门:http://java.sun.com/developer/technicalArticles/Programming/compression/

      【讨论】:

        【解决方案3】:

        将数据放入ByteArrayInputStream,然后您应该可以使用GZipInputStream对其进行解码。

        要从字符串中获取字节,请尝试getBytes("ISO-8859-1")。这种编码不会改变传入的字节数。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-08-31
          • 1970-01-01
          • 1970-01-01
          • 2015-01-25
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多