URL下载资源


public 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();
	}

}