求,字符串压缩变短的算法。

解决方案 »

  1.   

    public static void main(String[] args) throws Exception {
    try {
         // Encode a String into bytes
         String inputString = "LLLLLLLLLLLLLLLLLLLLLLLLLOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOONNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG??";
         byte[] input = inputString.getBytes("UTF-8");      // Compress the bytes
         byte[] output = new byte[100];
         Deflater compresser = new Deflater();
         compresser.setInput(input);
         compresser.finish();
         int compressedDataLength = compresser.deflate(output);
         System.out.println("Input string:" + inputString);
         System.out.println("Input length:" + input.length);
         System.out.println("Compressed length:" + compressedDataLength);
         System.out.println("Compressed string:" + new String(output));      // Decompress the bytes
         Inflater decompresser = new Inflater();
         decompresser.setInput(output, 0, compressedDataLength);
         byte[] result = new byte[100];
         int resultLength = decompresser.inflate(result);
         decompresser.end();      // Decode the bytes into a String
         String outputString = new String(result, 0, resultLength, "UTF-8");
         System.out.println("Decompressed string:" + outputString);
     } catch(java.io.UnsupportedEncodingException ex) {
         // handle
     } catch (java.util.zip.DataFormatException ex) {
         // handle
     }

    }
      

  2.   

    用 Java 自带的 zip 压缩算法就可以
    参考这个 http://www.java2000.net/viewthread.jsp?tid=4989
      

  3.   

    相关的Zip API ,http://gceclub.sun.com.cn/Java_Docs/html/zh_CN/api/java/util/zip/class-use/ZipEntry.html剩下的是程序员分内的事情,自己搞定。
      

  4.   

    大家给的都是压缩后字符串变成乱码的情况,我想知道的是类似于淘宝的这个
    http://list.mall.taobao.com/1307/g-s-----40-0--1307.htm
    在这个页面中搜索  中国  两个字 这个页面url就会变成
    http://list.mall.taobao.com/1307/g-s----g,23ilt6q-40-0--1307.htm实际上 这个 23ilt6q 就是中国两个字 压缩后变成的字符串。
      

  5.   


    这是压缩么???
    只是编码而已! 比如base64....
      

  6.   

    http://dev.csdn.net/author/Jason009/65c69cc4e34a4ef783c45add211105e0.html
    你看看这个