当前位置:编程学习 > wap >>

神奇的乱码怎么解决 有没有神来帮帮忙啊



public static String doGet(String url) {
if (url != null) {
if (UrlServer.checkNetworkInfo()) {
HttpGet httpRequest = new HttpGet(url);
httpRequest.addHeader("Accept-Encoding", "gzip");
HttpClient httpClient = getHttpClient();
HttpResponse httpResponse;
try {
httpResponse = httpClient.execute(httpRequest);
int code = httpResponse.getStatusLine().getStatusCode();
if (code == HttpStatus.SC_OK) {
HttpEntity httpEntity = httpResponse.getEntity();
InputStream is = httpEntity.getContent();
if (httpEntity.getContentEncoding() != null
&& httpEntity.getContentEncoding().getValue()
.contains("gzip")) {
is = new GZIPInputStream(is);
int i = -1;
byte[] b = new byte[1024];
StringBuilder sb = new StringBuilder();
while ((i = is.read(b)) != -1) {
sb.append(new String(b, 0, i,"utf-8"));
}
System.err.println(sb.toString());
return sb.toString();
}
return EntityUtils.toString(httpResponse.getEntity());

} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} else {
App.app.handler.sendEmptyMessage(1);
}
}
return null;
}
--------------------编程问答-------------------- 有一个字是乱码,乱码都是随机出现,出现的都是那一个地方!无语惨了。 --------------------编程问答-------------------- 授人于鱼,不如授人于渔,给楼主推荐一篇文章研究去吧:
http://www.ibm.com/developerworks/cn/java/j-lo-chinesecoding/index.html
补充:移动开发 ,  Android
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,