URL
eg: https://space.bilibili.com/
统一资源定位符定位资源的,定位互联网上的某一个资源
DNS域名解析:
协议://ip地址:端口/项目名/资源
//eg:
// https://next.xuetangx.com/
Url练习:
// 1.下载地址
URL url = new URL("https://blog.csdn.net/weixin_42751551/article/details/105871571");
// 2.连接到这个资源
HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();
InputStream inputStream = urlConnection.getInputStream();
FileOutputStream file = new FileOutputStream("1.jpg");
byte[] buffer = new byte[1024];
int len;
while ((len = inputStream.read(buffer))!=-1){
file.write(buffer, 0, len);
}
file.close();
inputStream.close();
urlConnection.disconnect();
学习地址:https://space.bilibili.com/95256449