使用zlib压缩来压缩数据。
//来 自 N o w J a v a . c o m //package com.nowjava; import java.io.ByteArrayOutputStream; import java.util.zip.Deflater; public class Main { public static void main(String[] argv) throws Exception { byte[] data = new byte[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 }; int offset = 2; int len = 2; System.out.println(java.util.Arrays.toString(deflateData(data, offset, len))); } /** * Compresses data using zlib compression. Uses default compression settings. * * @param data * The data to be compressed. * @return The compressed data. */ public static byte[] deflateData(byte[] data, int offset, int len) { ByteArrayOutputStream stream = new ByteArrayOutputStream( data.length); byte[] buffer = new byte[data.length];// from 时 代 Java 公 众 号 - nowjava.com Deflater def = new Deflater(); def.