无论用什么方法,,都是乱码
11-06 20:13:44.964 17265-18249/com.example.analyzesm.httpdemo I/DetailActivity: initData: �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
正在回答 回答被采纳积分+1
你的in ,baos,还有b没有任何关联呀。请参考
InputStream in = conn.getInputStream(); BufferedReader buffer = new BufferedReader(new InputStreamReader(in)); StringBuffer bs = new StringBuffer(); String str = null; while((l=buffer.readLine())!=null){ bs.append(str); } Log.d(TAG,bs.toString());
祝:学习愉快
new Thread(){
@Override
public void run() {
super.run();
try {
URL url = new URL("http://www.imooc.com/api/teacher?type=3&cid=1");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(6000);
conn.setRequestMethod("GET");
int Rscode = conn.getResponseCode();
if(Rscode == 200){
InputStream in = conn.getInputStream();
byte[] b = new byte[1024*512];
int len;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
while ((len = in.read())!=-1){
baos.write(b,0,len);
}
byte[] s = baos.toByteArray();
Log.i(TAG, "initData: "+new String(s,"utf-8"));
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}.start();
- 参与学习 人
- 提交作业 307 份
- 解答问题 1613 个
本专题是联网及数据处理的必备技能。课程从网络基础知识到线程间协同工作、异步下载处理。介绍了Android内外部文件存储、轻量级数据库SQLite的使用。利用屏幕适配、状态保持、百度地图解决实际问题。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星