英文:
is it possible to convert a Gzip byte array to String?
问题
我能够使用GZIP Java压缩方法压缩一个Base64字符串,因此可以在一个字符串中获取压缩后的值吗?
英文:
i am able to compress a base64 string areng the GZIP java compression method, so it is possible to get the compressed value in a st
ring?
答案1
得分: 1
可以使用以下方法将gzip解压缩为字符串:
public static String decompress(byte[] byteArray) throws Exception {
if (byteArray == null ) {
return null;
}
GZIPInputStream gzis = new GZIPInputStream(new ByteArrayInputStream(byteArray));
BufferedReader bfr = new BufferedReader(new InputStreamReader(gzis, "UTF-8"));
String outputString = "";
String line;
while ((line=bfr.readLine())!=null) {
outputString += line;
}
return outputString;
}
英文:
Yes, you can decompress gzip to string with this method.
public static String decompress(byte[] byteArray) throws Exception {
if (byteArray == null ) {
return null;
}
GZIPInputStream gzis = new GZIPInputStream(new ByteArrayInputStream(byteArray));
BufferedReader bfr = new BufferedReader(new InputStreamReader(gzis, "UTF-8"));
String outputString = "";
String line;
while ((line=bfr.readLine())!=null) {
outputString += line;
}
return outputString;
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论