The input string is the gzencodecompressed string of PHP. you can use gzdecodeto open it, but use java.util.zip of Java. when GZIPInputStream reads a string, it always prompts java.util.zip. zipException: NotinGZIPformat. I hope some experienced users can help me solve the problem. my code is as follows: & quot; JAVAimportjava. io. byteArrayInputStream; importjava. io. byteArrayOutputStream; imp... phpjavagzdecode
The input string is the gzencodecompressed string of PHP. you can use gzdecodeto extract the string. However, when you use java.util.zip. GZIPInputStream of Java to read the string, the following message is always displayed:
Java.util.zip. ZipException: Not in GZIP format
I hope some experienced friends can help me solve the problem. my code is as follows:
JAVAimport java. io. byteArrayInputStream; import java. io. byteArrayOutputStream; import java. io. inputStream; import java. io. outputStream; import java.util.zip. GZIPInputStream; import java.util.zip. GZIPOutputStream; public class Gzdecode {public static void decompress (InputStream is, OutputStream OS) throws Exception {GZIPInputStream gis = new GZIPInputStream (is); int count; byte data [] = new byte [BUFFER]; While (count = gis. read (data, 0, BUFFER ))! =-1) {OS. write (data, 0, count);} gis. close ();} public static byte [] decompress (byte [] data) throws Exception {ByteArrayInputStream bais = new ByteArrayInputStream (data); ByteArrayOutputStream baos = new ByteArrayOutputStream (); // decompress (bais, baos); data = baos. toByteArray (); baos. flush (); baos. close (); bais. close (); return data;} public static void main (String [] args) throws Exception {String input = ""; byte [] data = input. getBytes ("UTF-8"); byte [] data_decompress = decompress (data); System. out. write (data_decompress );