0
点赞
收藏
分享

微信扫一扫

通过URL解析下载资源

飞鸟不急 2023-01-17 阅读 96


package com.tencent.UDP;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class Download {
public static void main(String[] args) throws IOException {
URL url = new URL("http://m.0714news.com/videos/b4e0ba24a77940aa.mp4");

HttpURLConnection u = (HttpURLConnection)url.openConnection();

InputStream is = u.getInputStream();

FileOutputStream fos = new FileOutputStream("C://Users//mibook//Desktop//jay.mp4");

byte[] buffer = new byte[1024];
int len = 0;
while((len = is.read(buffer)) != -1) {
fos.write(buffer , 0 , buffer.length);
System.out.println(buffer);
}

fos.close();
is.close();
u.disconnect();
}
}

 

举报

相关推荐

0 条评论