我们如何使用JAVA下载HTML页面? [英] How we can Download a HTML Page using JAVA?
本文介绍了我们如何使用JAVA下载HTML页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用JAVA下载HTML页面?
解决方案
以下是代码:
public static String savePage(final String URL)throws IOException {
String line =,all =;
URL myUrl = null;
BufferedReader in = null;
尝试{
myUrl =新的URL(URL);
in = new BufferedReader(new InputStreamReader(myUrl.openStream())); ((line = in.readLine())!= null){
all + = line;
while
}
} finally {
if(in!= null){
in.close();
}
}
return all;
}
现在你可以在while循环中处理一行一行。 p>
How we can Download a HTML Page using JAVA??
解决方案
Here is the code:
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;
}
Now you can process one line after one other in the while loop.
这篇关于我们如何使用JAVA下载HTML页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文