网络编程
作者:互联网
网络编程
IP
abcd地址分类 0-255对半分
如何查看IP,查看java帮助文档 中该类。
端口
通信协议
ULR
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class UrlDown {
public static void main(String[] args) throws IOException {
//1.下载地址
URL url = new URL("https://m701.music.126.net/20210111112635/1d76165639698f6ac64f02860722014c/jdyyaac/obj/w5rDlsOJwrLDjj7CmsOj/5546003514/e409/aed6/f93a/e0f802f6dbe22026d98c0129ec474324.m4a");
//2.连接这个资源HTTP
HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();
//3.io流读取
InputStream inputStream = urlConnection.getInputStream();
FileOutputStream fos = new FileOutputStream("4.m4a");
byte[] buffer = new byte[1024];
int len;
while ((len=inputStream.read(buffer))!=-1){
fos.write(buffer,0,len);
}
//4.逐层关闭资源
fos.close();
inputStream.close();
urlConnection.disconnect();
}
}
标签:urlConnection,java,fos,编程,网络,inputStream,io,import 来源: https://blog.csdn.net/qq_46728644/article/details/112427271