首页| JavaScript| HTML/CSS| Matlab| PHP| Python| Java| C/C++/VC++| C#| ASP| 其他|
购买积分 购买会员 激活码充值

您现在的位置是:虫虫源码 > Java > Android 使用HttpURLConnection打开连接读取内容(流)

Android 使用HttpURLConnection打开连接读取内容(流)

  • 资源大小:8.30 kB
  • 上传时间:2021-06-30
  • 下载次数:0次
  • 浏览次数:0次
  • 资源积分:1积分
  • 标      签: ASP源码

资 源 简 介

Android 使用HttpURLConnection打开连接读取内容(流),使用循环来读取获得的数据:   try   {    // 使用HttpURLConnection打开连接    HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();    // 得到读取的内容(流)    InputStreamReader in = new InputStreamReader(urlConn.getInputStream());    // 为输出创建BufferedReader    BufferedReader buffer = new BufferedReader(in);    String inputLine = null;    // 使用循环来读取获得的数据    while (((inputLine = buffer.readLine()) != null))    {    // 我们在每一行后面加上一个" "来换行    resultData += inputLine + " ";    }    // 关闭InputStreamReader    in.close();    // 关闭http连接    urlConn.disconnect();    // 设置显示取得的内容    if (resultData != null)    {    mTextView.setText(resultData);    }    else    {    mTextView.setText("读取的内容为NULL");    }   }

文 件 列 表

srcfans.com
URLConnection
.project
URLConnection
URLConnection
.classpath
srcfans.com
VIP VIP
0.178418s