针对某些场景下,面对服务文件大,或者服务端服务器不稳定时使用该模块。功能代码如下:
import java.io.File;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import java.net.HttpURLConnection;import java.net.URL;public class MultiFileDownLoad { private static int position = 0; public static void doDownLoad(String url){ File targetFile=new File(MultiFileDownLoad.class.getResource("").getFile()); targetFile=targetFile.getParentFile(); targetFile=targetFile.getParentFile(); targetFile=targetFile.getParentFile(); targetFile=targetFile.getParentFile(); targetFile=new File(targetFile.getAbsolutePath()+File.separator+ System.currentTimeMillis()+".wmv"); if(!targetFile.exists()){ try { targetFile.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } //File targetFile=new File("D://video.wmv"); writeFile(url,targetFile); } private static InputStream getInputStream(String url,long startPosition){ InputStream inputStream=null; HttpURLConnection conn=null; try { URL filePath=new URL(url); conn= (HttpURLConnection) filePath.openConnection(); conn.setConnectTimeout(3*1000); //防止屏蔽程序抓取而返回403错误 conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)"); long contentLength=conn.getContentLengthLong(); if(startPosition