这里以下载迅雷U享版为例。
示例代码:

package com.zifeiy.snowflake.handle.filesget;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class HttpFileGetter {
	
	public boolean download(String urlString, File localFile) {
		try {
			URL url = new URL(urlString);
			URLConnection connection = url.openConnection();
			connection.setConnectTimeout(5*1000);
			InputStream inputStream = connection.getInputStream();
			byte[] byteArr = new byte[1024];
			int len;
			File dir = localFile.getParentFile();
			if (dir.exists() == false) 
				dir.mkdirs();
			OutputStream outputStream = new FileOutputStream(localFile);
			while ((len = inputStream.read(byteArr)) != -1) {
				outputStream.write(byteArr, 0, len);
			}
			outputStream.close();
			inputStream.close();
		} catch (IOException e) {
			e.printStackTrace();
			return false;
		}
		
		return true;
	}
	
	// main for test
	public static void main(String[] args) {
		HttpFileGetter httpFileGetter = new HttpFileGetter();
		httpFileGetter.download("http://down.sandai.net/ThunderVIP/ThunderVIP-xlgw.exe", new File("D:\\test_download.exe"));
	}
}

下载下来的程序运行也没有问题:
Java下载HTTP URL链接示例

相关文章:

  • 2021-10-11
  • 2022-02-08
  • 2021-11-03
  • 2022-02-04
  • 2021-11-05
  • 2021-06-04
  • 2021-04-20
  • 2021-09-01
猜你喜欢
  • 2021-09-13
  • 2021-09-10
  • 2022-12-23
  • 2022-12-23
  • 2021-08-08
  • 2022-12-23
  • 2021-05-31
相关资源
相似解决方案