1.URL
Uniform Resource Locator:统一资源定位器
举例:https://www.google.com.hk/webhp?hl=zh-CN&sourceid=cnhp
格式:网络协议 // IP地址 :端口号 / 项目名 /资源
2.用URL下载网络资源
package net;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
public class Download {
public static void main(String[] args) throws Exception {
URL url = new URL("https://s2.music.126.net/style/web2/img/coverall.png?eb6f9099e509ad142b3c5f0fdd7a8af5");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
InputStream inputStream = urlConnection.getInputStream();
FileOutputStream fileOutputStream = new FileOutputStream("1.png");
byte[] buffer = new byte[1024];
int len;
while((len=inputStream.read(buffer))!=-1){
fileOutputStream.write(buffer,0,len);
}
fileOutputStream.close();
inputStream.close();
urlConnection.disconnect();
}
}