阅读Android的URL的内容 [英] Read contents of a URL in Android

查看:234
本文介绍了阅读Android的URL的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的Andr​​oid和我试图找出如何获得一个URL的内容作为一个字符串。例如,如果我的网址是 http://www.google.com/ 我想要得到的HTML页面为一个字符串。谁能帮我这个?

I'm new to android and I'm trying to figure out how to get the contents of a URL as a String. For example if my URL is http://www.google.com/ I want to get the HTML for the page as a String. Could anyone help me with this?

推荐答案

从Java文档:的 readingURL

URL yahoo = new URL("http://www.yahoo.com/");
BufferedReader in = new BufferedReader(
            new InputStreamReader(
            yahoo.openStream()));

String inputLine;

while ((inputLine = in.readLine()) != null)
    System.out.println(inputLine);

in.close();

而不是写每一行的System.out 只是将其追加到一个字符串。的

Instead of writing each line to System.out just append it to a string.

这篇关于阅读Android的URL的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆