Compress String

How to compress a String (algorithem)?

Questions by Darsh_singh

Showing Answers 1 - 1 of 1 Answers

Code
  1. import java.io.ByteArrayOutputStream;

  2. java.io.IOException;

  3. import java.util.zip.GZIPOutputStream;

  4. import java.util.zip.*;

  5.  

  6. public class zipUtil{

  7. public static String compress(String str){

  8.     if (str == null || str.length() == 0) {

  9.         return str;

  10.     }


  11.     GZIPOutputStream gzip = new GZIPOutputStream(out);

  12.     gzip.write(str.getBytes());

  13.     gzip.close();

  14.     return out.toString("ISO-8859-1");

  15.  }

  16.  

  17.  public static void main(String[] args) throws IOException {

  18. String string = "admin";

  19.     System.out.println("after compress:");

  20.     System.out.println(ZipUtil.compress(string));

  21.  

  22.   }

  23. }

  24.  



  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions