使用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());
}
}
原文地址:https://www.cnblogs.com/Mr-quin/p/8585191.html
时间: 2024-10-26 21:05:27