HttpClient中文乱码的问题

// InputStream转String(UTF-8)

public String inputStream2String(InputStream in) throws IOException {

StringBuffer out = new StringBuffer();

byte[] b = new byte[4096];

for (int n; (n = in.read(b)) != -1;) {

//like12 modified,20180713,解决中文乱码的bug

//out.append(new String(b, 0, n));//默认GBK编码(系统编码)

out.append(new String(b, 0, n, "UTF-8"));//指定编码格式

}

return out.toString();

}

//GBK转UTF-8

msg = new String(msg.getBytes("GBk"),"UTF-8");

System.out.println("msg2:" + msg);

猜你喜欢

转载自blog.csdn.net/tanzongbiao/article/details/82528657
今日推荐