Java: Error creating a GZIPInputStream: Not in GZIP format

前端 未结 3 2218
暖寄归人
暖寄归人 2020-12-17 23:39

I am trying to use the following Java code to compress and uncompress a String. But the line that creates a new GZipInputStream object out of a new ByteArrayInputStream obj

3条回答
  •  抹茶落季
    2020-12-18 00:22

    You encoded baostream to a string with your default platform encoding, probably UTF-8. You should be using baostream.getBytes() to work with binary data, not strings.

    If you insist on a string, use an 8-bit encoding, e.h. baostream.toString("ISO-8859-1"), and read it back with the same charset.

提交回复
热议问题