网络请求结果出现乱码,求指点怎么改

lucers 2016-10-18 05:29:31

// 通过url获取数据
public static String Getpath(String path) {
StringBuffer buffer = new StringBuffer();
URL url;
try {
url = new URL(path);
HttpURLConnection connection = (HttpURLConnection) url
.openConnection();
InputStream stream = connection.getInputStream();
byte[] by = new byte[1024];
int len = 0;
while ((len = stream.read(by)) != -1) {
buffer.append(new String(by, 0, len, "UTF-8"));
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Log.e("TAG", buffer.toString());
return buffer.toString();
}

log里面打印结果有乱码出现了,求指点
...全文
140 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
头发还没秃a 2016-10-19
  • 打赏
  • 举报
回复
String str = new String(buffer.toString().getBytes("iso8859-1"),"UTF-8");
stevefat 2016-10-18
  • 打赏
  • 举报
回复
可能不是urf-8 的格式

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧