Android 打开网络连接

使用url打开网络连接

String urlString = "http://"+et_url.getText()+"";
if(urlString.length()>0){
    try {
    String line = "";
    URL url = new URL(urlString);
    URLConnection urlConnection = url.openConnection();
     BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
     while ((line = bufferedReader.readLine())!=null){
           if(line.indexOf("a href")>=0)
                 tv_url.setText(line);
            }
            bufferedReader.close();
            urlConnection.getInputStream().close();
       } catch (Exception e) {
            e.printStackTrace();
            tv_url.setText(e.toString());
      }
}
posted @ 2018-03-16 20:57  秦川德利齐  阅读(463)  评论(0编辑  收藏  举报