ITeye博客

获得URL的内容

chengjie177 · 2012-08-30 14:47 · 互联网 · Markdown

try {
    // Create a URL for the desired page
    URL url = new URL("http://hostname:80/index.html");

    // Read all the text returned by the server
    BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
    String str;
    while ((str = in.readLine()) != null) {
        // str is one line of text; readLine() strips the newline character(s)
    }
    in.close();
} catch (MalformedURLException e) {
} catch (IOException e) {
}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。