Import Java. io. bytearrayinputstream; import Java. io. bytearrayoutputstream; import Java. io. ioexception; import java.util.zip. gzipinputstream; import java.util.zip. gzipoutputstream; public class stringcompression {static string code = "UTF-8"; public static string compress (string Str) throws ioexception {system. out. println ("the size of the string before compression:" + Str. length (); If (STR = NULL | Str. length () = 0) {return STR;} bytearrayoutputstream out = new bytearrayoutputstream (); gzipoutputstream gzip = new gzipoutputstream (out); gzip. write (Str. getbytes (); gzip. close (); Return out. tostring ("ISO-8859-1");} public static string uncompress (string Str) throws ioexception {system. out. println ("compressed string size:" + Str. length (); If (STR = NULL | Str. length () = 0) {return STR;} bytearrayoutputstream out = new bytearrayoutputstream (); bytearrayinputstream in = new bytearrayinputstream (Str. getbytes ("ISO-8859-1"); gzipinputstream gunzip = new gzipinputstream (in); byte [] buffer = new byte [256]; int N; while (n = gunzip. read (buffer)> = 0) {out. write (buffer, 0, n);} return out. tostring ();} public static void main (string [] ARGs) throws ioexception {system. out. println (stringcompression. compress ("success"); system. out. println (stringcompression. uncompress (stringcompression. compress ("fsafgdfdsgfdgfdghfhgfhgfhdgdsfagdsgdasgddddddddddddddddddddddddd ")));}}