public class UrlDown {
public static void main(String[] args) throws Exception {
//1、下载地址
URL url = new URL("https://m701.music.126.net/20210719125031/8ba2fcc65c0ff15d27fc84875d715980/jdyyaac/obj/w5rDlsOJwrLDjj7CmsOj/9819321370/9a77/6b62/7072/9b5c1d6e180149435269100e170c69fb.m4a");
//2、连接到这个资源 HTTP
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
InputStream inputStream = urlConnection.getInputStream();
FileOutputStream fos = new FileOutputStream("E:\\demo\\70c69fb.m4a");
byte[] buffer = new byte[1024];
int len;
while ((len=inputStream.read(buffer))!=-1){
//写出这个数据
fos.write(buffer,0,len);
}
fos.close();
inputStream.close();
//断开连接
urlConnection.disconnect();
}
URL网络下载文件
最新推荐文章于 2022-10-10 21:49:51 发布