//java.util.zip.Deflater & Inflater
//demo from Sun: // Encode a String into bytes
String inputString = "blahblahblah??";
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); // 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");
//demo from Sun: // Encode a String into bytes
String inputString = "blahblahblah??";
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); // 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");
String s = "Some string!!!";
BytedArrayOutputStream bos = new BytedArrayOutputStream();
BufferedWriter bw = new BufferedWriter( new OutputStreamWriter( new ZipOutputStream( bos ) ) );
bw.print( s );
bw.flush();
byte[] bs = bos.toByteArray();
bw.close();
然后把字符串打到这个writer里面
最后通过byte array的outputstream得到byte array
to wobelisk() :压缩的数据格式是什么格式?除了用Inflater来解压外,还能用别的什么解压缩的,比如zip
to kenli(致虚子):你的方法我试了试,但是没有成功,不过还是谢谢你,我会接着考虑,希望你也能继续支持!