gzip解码中文乱码问题 我通过jpcap抓获网络中传输的gzip加密数据包,通过GZIPInputStream进行解压,结果英文能正常解压出来,中文解压出来的是乱码。求高人指点 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 // 建立grip压缩文件输入流 InputStream fin = new ByteArrayInputStream(contentbyte); /** * 测试时候进入gzip解码 */ System.out.println("\n\n\n\nGZIP!\n\n\n\n"); try { // 建立gzip解压工作流 GZIPInputStream gzin = new GZIPInputStream(fin); byte[] buf = new byte[1024]; ArrayList<byte[]> cb = new ArrayList<byte[]>(); int num, len = 0; while ((num = gzin.read(buf, 0, buf.length)) != -1) { byte[] cell = new byte[num]; len += num; System.arraycopy(buf, 0, cell, 0, num); cb.add(cell); } contentbyte = new byte[len]; num = 0; for (byte[] c : cb) { System.arraycopy(c, 0, contentbyte, num, c.length); num += c.length; } gzin.close(); fin.close(); contentbyte里面存储的是网上传输的网页内容,包括英文字符,还有中文字符。 将contentbyte的内容转字符串时,有指定编码么? 写一个Character过滤器,搞定一切乱码. Java 日历·报错 javac Hello.java时,找不到Hello.java文件 求助数据库连接。急迫! 请教一个线程控制的问题. 关于画图的问题 return语句,,大家来看看那种代码风格比较好. JDBC、reflect调用时候的费解事情,关于object的argument type mismatch 小问题: Tomcat+Oracle问题 ***Java 学的好辛苦啊,想了好几天还是不明白啊:(*** 初学张孝祥DOM 疑问 急 请教2个正则表达式怎么写
InputStream fin = new ByteArrayInputStream(contentbyte); /**
* 测试时候进入gzip解码
*/
System.out.println("\n\n\n\nGZIP!\n\n\n\n"); try {
// 建立gzip解压工作流
GZIPInputStream gzin = new GZIPInputStream(fin); byte[] buf = new byte[1024];
ArrayList<byte[]> cb = new ArrayList<byte[]>();
int num, len = 0;
while ((num = gzin.read(buf, 0, buf.length)) != -1) {
byte[] cell = new byte[num];
len += num;
System.arraycopy(buf, 0, cell, 0, num);
cb.add(cell);
}
contentbyte = new byte[len];
num = 0;
for (byte[] c : cb) {
System.arraycopy(c, 0, contentbyte, num, c.length);
num += c.length;
} gzin.close();
fin.close();