Android 中文乱码问题

Java代码   收藏代码
  1. EncodingUtils.getString(data.getBytes("GB2312"), "UTF-8");      


如果直接getBytes()的话是以iso88590-1编码获取字节。

 

 

 

 

Java代码   收藏代码
  1. URL myFileUrl = null;     
  2.   
  3. myFileUrl = new URL(url);  
  4.   
  5. HttpURLConnection conn;  
  6. conn = (HttpURLConnection) myFileUrl.openConnection();  
  7. conn.setDoInput(true);  
  8. conn.connect();  
  9. InputStream is = conn.getInputStream();  
  10. BufferedReader br = new BufferedReader(new InputStreamReader(is,  
  11.   "GB2312"));  
  12.   
  13. sb = new StringBuffer();  
  14. String data = "";  
  15.   
  16. while ((data = br.readLine()) != null) {     
  17.      sb.append(data+"\n");     
  18. }     
  19. String result = sb.toString();  

 

 

 

 

 

Java代码   收藏代码
  1. sb = new StringBuffer();     
  2. HttpEntity entity = response.getEntity();     
  3. InputStream is = entity.getContent();     
  4. BufferedReader br = new BufferedReader(     
  5.         new InputStreamReader(is,"GB2312"));     
  6. String data = "";     
  7.   
  8. while ((data = br.readLine()) != null) {     
  9.     sb.append(data);     
  10. }     
  11. String result = sb.toString();    

 

 

 

 

 

Java代码   收藏代码
  1. public void readTxt(){  
  2.   
  3. ByteArrayBuffer sb = new ByteArrayBuffer(5000);  
  4. try {  
  5. InputStream ip = asset.open("aa.txt");  
  6. BufferedReader br = new BufferedReader(new InputStreamReader(ip,"GB2312"));  
  7.   
  8. String temp = null;  
  9. int cur =0;  
  10. // while((temp = br.readLine())!=null){  
  11. // sb.append(temp);  
  12. // }  
  13. while((cur = br.read())!=-1){  
  14. sb.append(cur);  
  15. }  
  16.   
  17. textView.setText( EncodingUtils.getString(sb.toByteArray(),"GB2312"));    
  18. catch (IOException e) {  
  19. // TODO Auto-generated catch block  
  20. e.printStackTrace();  
  21. }  

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值