我需要将字符串转换为 gzip base64。我有这个代码
import java.util.zip.GZIPOutputStream;
import org.apache.commons.codec.binary.Base64OutputStream;
public class Test {
public static void main(String[] args) {
String text = "a string of characters";
try {
ByteArrayOutputStream os = new ByteArrayOutputStream();
Base64OutputStream b64os = new Base64OutputStream(os);
GZIPOutputStream gzip = new GZIPOutputStream(b64os);
gzip.write(text.getBytes("UTF-8"));
String base64 = new String(os.toByteArray(),"UTF-8");
gzip.close();
b64os.close();
System.out.print(base64)
} catch (Throwable t) {
t.printStackTrace();
}
}
}
我需要得到H4sIAAAAAAAAAEtUKC4pysxLV8hPU0jOSCxKTC5JLSoGAOP+cfkWAAAA
。为什么我得到这个输出?
H4sIAAAAAAAA