Is there any way to convert Java String
to a byte[]
( not the boxed Byte[]
)?
(有没有办法将Java String
转换为byte[]
( 不是盒装的Byte[]
)?)
In trying this:
(在尝试这个:)
System.out.println(response.split("
")[1]);
System.out.println("******");
System.out.println(response.split("
")[1].getBytes().toString());
and I'm getting separate outputs.
(而我正在获得单独的输出。)
Unable to display 1st output as it is a gzip string.(无法显示第一个输出,因为它是一个gzip字符串。)
<A Gzip String>
******
[B@38ee9f13
The second is an address.
(第二个是地址。)
Is there anything I'm doing wrong?(有什么我做错了吗?)
I need the result in abyte[]
to feed it to gzip decompressor, which is as follows. (我需要在byte[]
中将结果提供给gzip decompressor,如下所示。)
String decompressGZIP(byte[] gzip) throws IOException {
java.util.zip.Inflater inf = new java.util.zip.Inflater();
java.io.ByteArrayInputStream bytein = new java.io.ByteArrayInputStream(gzip);
java.util.zip.GZIPInputStream gzin = new java.util.zip.GZIPInputStream(bytein);
java.io.ByteArrayOutputStream byteout = new java.io.ByteArrayOutputStream();
int res = 0;
byte buf[] = new byte[1024];
while (res >= 0) {
res = gzin.read(buf, 0, buf.length);
if (res > 0) {
byteout.write(buf, 0, res);
}
}
byte uncompressed[] = byteout.toByteArray();
return (uncompressed.toString());
}
ask by Mkl Rjv translate from so