下载文件时,可以多线程分段下载,每个线程都负责下载一部分
public class Demo { public static void main(String[] args) { String path="http://softforspeed.51xiazai.cn/down/BaiduNetdisk_6.9.7.4.exe"; try { URL url = new URL(path); HttpURLConnection cnn = (HttpURLConnection) url.openConnection(); cnn.setConnectTimeout(5000);//请求超时时间 cnn.setReadTimeout(5000);//读取超时时间 cnn.setRequestMethod("GET");//设置请求提交的方法 int responseCode = cnn.getResponseCode();//获取响应码 System.out.println("responseCode = " + responseCode); //如果连接ok 200 if(responseCode==200){ //设计分段下载 int contentLength = cnn.getContentLength();//总长度 //获取它的长度 System.out.println("contentLength = " + contentLength); //五部分 每一部分长度/大小 int i = conten