我想把python代码重写成java。这是python代码:
zipped = zlib.compress(data_json_upload.encode("utf-8"))
print ("data encode")
print (zipped)
base64_bytes = base64.b64encode(zipped)
base64_string = base64_bytes.decode('utf-8')
这是我的java代码: *你知道吗
byte[] bytes = inputString.getBytes("UTF-8");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream os = new GZIPOutputStream(baos);
os.write(bytes, 0, bytes.length);
os.close();
byte[] result = baos.toByteArray();
System.out.println(result);
byte [] base64=Base64.encodeBase64(result);
String send= new String(base64,"UTF-8");
你知道吗* 但是,它们似乎对同一个字符串返回不同的结果。你知道我能做些什么来得到同样的代码在java上工作吗? 例如,在java中发送与在java中发送base64\u字符串不同的内容
GZIPOutputStream
将生成一个*.gz
文件。如果您只需要一个zlib流,请使用^{相关问题 更多 >
编程相关推荐