开发学院手机开发Android 开发 Android中文乱码彻底解决 阅读

Android中文乱码彻底解决

 2010-09-07 10:51:00 来源:WEB开发网   
核心提示:以下是我研究的成果,希望对您有帮助:Java代码sb = new StringBuffer();HttpEntity entity = response.getEntity();InputStream is = entity.getContent();BufferedReader br = new BufferedRe

以下是我研究的成果,希望对您有帮助:

Java代码

sb = new StringBuffer();

HttpEntity entity = response.getEntity();

InputStream is = entity.getContent();

BufferedReader br = new BufferedReader(

new InputStreamReader(is,"GB2312"));

String data = "";

while ((data = br.readLine()) != null) {

sb.append(data);

}

String result = sb.toString();

sb = new StringBuffer();

HttpEntity entity = response.getEntity();

InputStream is = entity.getContent();

BufferedReader br = new BufferedReader(

new InputStreamReader(is,"GB2312"));

String data = "";

while ((data = br.readLine()) != null) {

sb.append(data);

}

String result = sb.toString();

Java代码

//下面的是多余的代码,平台会按照默认编码读数据,谢谢melode11和eleda指点 result = new String(result.getBytes(),"UTF-8");

//下面的是多余的代码,平台会按照默认编码读数据,谢谢melode11和eleda指点 result = new String(result.getBytes(),"UTF-8");

我解释一下,

Java代码

BufferedReader br = new BufferedReader(

new InputStreamReader(is,"GB2312"));

BufferedReader br = new BufferedReader(

new InputStreamReader(is,"GB2312"));

是读取要改编码的源,源的格式是GB2312的,安源格式读进来,然后再对源码转换成想要的编码就行

Tags:Android 乱码

编辑录入:coldstar [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
更多精彩
    赞助商链接

    热点阅读
      焦点图片
        最新推荐
          精彩阅读