`
sdylag
  • 浏览: 75706 次
  • 性别: Icon_minigender_1
  • 来自: 云南
社区版块
存档分类
最新评论

ByteArrayOutputStream 转为 String 出现的乱码问题

    博客分类:
  • JAVA
 
阅读更多

                            InputStream is = conn.getInputStream();

           ByteArrayOutputStream baos = new ByteArrayOutputStream();

          

           byte[] buffer = new byte[1024];

           int len = -1;

           while((len = is.read(buffer)) != -1){

              baos.write(buffer , 0 , len);

           }

           baos.close();

           is.close();

             

           String result = new String( baos.toByteArray());

           /*

           * 到此步骤时:Debug-Watch 查看值:

           *      1.baos对象中含有中文  无乱码;

           *      2.result 对象中含有中文  出现乱码!

           */

 

           //解决此问题办法:

           byte[] lens = baos.toByteArray();

           String result = new String(lens);//result结果显示正常:含中文无乱码

分享到:
评论
1 楼 文艺吧网 2017-05-16  
还有一个GZIP的问题,我怎么转都乱码最后是因为要解压一下http://www.sojson.com/blog/227.html

相关推荐

Global site tag (gtag.js) - Google Analytics