java通过url获取网页内容_Java语言通过URL读取网页数据并保存到本地文件(代码实例)...
本文主要向大家介紹了Java語言通過URL讀取網頁數據并保存到本地文件(代碼實例),通過具體的內容向大家展示,希望對大家學習JAVA語言有所幫助。
Java通過URL讀取網頁數據并保存到本地文件(代碼實例)
import?java.io.*;
import?java.net.MalformedURLException;
import?java.net.URL;
import?java.net.URLConnection;
public?class?URLFile?{
public?static?void?main(String[]?args)?throws?FileNotFoundException?{
URL?url?=?null;
try?{
url?=?new?URL("https://acm.sdut.edu.cn/");
File?fp?=?new?File("E:/test.html");
OutputStream?os?=?new?FileOutputStream(fp);
URLConnection?conn?=?url.openConnection();
BufferedReader?in?=?new?BufferedReader(new?InputStreamReader(conn.getInputStream()));
String?urlString?=?"";
String?current;
while?((current?=?in.readLine())?!=?null)?{
urlString?+=?current;
}
os.write(urlString.getBytes());
os.close();
}?catch?(MalformedURLException?e)?{
e.printStackTrace();
}?catch?(IOException?e)?{
e.printStackTrace();
}
}
}
本文由職坐標整理并發布,希望對同學們有所幫助。了解更多詳情請關注編程語言JAVA頻道!
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的java通过url获取网页内容_Java语言通过URL读取网页数据并保存到本地文件(代码实例)...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: xmapp 查询文字内容显示乱码
- 下一篇: 近似值匹配