我们如何使用JAVA下载HTML页面?

2024-02-04

我们如何使用JAVA下载HTML页面?


这是代码:

public static String savePage(final String URL) throws IOException {
    String line = "", all = "";
    URL myUrl = null;
    BufferedReader in = null;
    try {
        myUrl = new URL(URL);
        in = new BufferedReader(new InputStreamReader(myUrl.openStream()));

        while ((line = in.readLine()) != null) {
            all += line;
        }
    } finally {
        if (in != null) {
            in.close();
        }
    }

    return all;
}

现在您可以在 while 循环中一行接一行地处理。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

我们如何使用JAVA下载HTML页面? 的相关文章

随机推荐