URL下载资源
2021-02-05 04:16
标签:throws url string class java obj tst aac throw URL下载资源 标签:throws url string class java obj tst aac throw 原文地址:https://www.cnblogs.com/zhang-han/p/14370465.htmlpublic class URLDownload {
public static void main(String[] args) throws IOException {
URL url=new URL("https://m10.music.126.net/20210204001424/b2ecdfbfe13e0b8bb4246a9ea827eeae/yyaac/obj/wonDkMOGw6XDiTHCmMOi/2025798093/8cc2/2f5e/bc24/4d305f5b282b778fca0c8c57f08ebe7e.m4a");
HttpURLConnection uc=(HttpURLConnection)url.openConnection();
InputStream is=uc.getInputStream();
FileOutputStream fos=new FileOutputStream(new File("d:/a"));
byte[] buffer=new byte[1024];
int len;
while((len=is.read(buffer))!=-1) {
fos.write(buffer,0,len);
}
fos.close();
is.close();
uc.disconnect();
}
}