gz压缩 解压

//压缩
public static String Compress(String data) {
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DeflaterOutputStream zos = new DeflaterOutputStream(bos);
zos.write(data.getBytes());
zos.close();
return new String(new BASE64Encoder().encode(bos.toByteArray())).replaceAll("\r", "").replaceAll("\n", "");
} catch (Exception ex) {
ex.printStackTrace();
return "压缩失败";
}
}
//解压缩
public static String DeCompress(String encdata) {
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
InflaterOutputStream zos = new InflaterOutputStream(bos);
zos.write(new BASE64Decoder().decodeBuffer(encdata));
zos.close();
return new String(bos.toByteArray());
} catch (Exception ex) {
ex.printStackTrace();
return "解压缩失败";
}
}


用gzcompress和gzuncompress解决了
和java的DeflaterOutputStream压缩算法一样!
http://bbs.csdn.net/topics/360040787

你可能感兴趣的:(压缩)