我试图使用以下代码在php中压缩一个String。
<?php
$compressed = gzcompress('Compress me', 9);
echo $uncompressed;
?>
The compressed string is "xÚsÎÏ-(J-.VÈM½?".
但是当尝试使用以下函数在java中解压缩时
public static String unzipString(String zippedText) {
String unzipped = null;
try {
byte[] zbytes = zippedText.getBytes("ISO-8859-1");
// Add extra byte to array when Inflater is set to true
byte[] input = new byte[zbytes.length + 1];
System.arraycopy(zbytes, 0, input, 0, zbytes.length);
input[zbytes.length] = 0;
ByteArrayInputStream bin = new ByteArrayInputStream(input);
InflaterInputStream in = new InflaterInputStream(bin);
ByteArrayOutputStream bout = new ByteArrayOutputStream(512);
int b;
while ((b = in.read()) != -1) {
bout.write(b);
}
bout.close();
unzipped = bout.toString();
} catch (IOException io) {
printIoError(io);
}
return unzipped;
}
我得到了null string ..如果我做错了这段代码,请纠正我。