首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

ByteArrayOutputStream 转为 String 出现的乱码有关问题

2012-08-30 
ByteArrayOutputStream 转为 String 出现的乱码问题??????????????????????????? InputStream is conn.g

ByteArrayOutputStream 转为 String 出现的乱码问题

??????????????????????????? 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结果显示正常:含中文无乱码

热点排行