批下载文件,不做过多解释
1、主方法调用
完整下载四参为零,断点下载四参索引不为零
public static void main(String[] args) throws IOException {
download(45,230,"f40bbc",0,3);
}
2、下载
indexMain 主索引
indexSub 次索引
folder 文件夹、文件名
number 支持断点
indexMax 最大索引
public static void download(int indexMain,int indexSub,String folder,int number,int indexMax) throws IOException{
createFolder(folder);
int n = 0;
if(number!=0){n = number;}
for(;n<indexMax+1;n++){
System.out.println("正在执行(已执行"+n+"次),已完成 "+((float)n/indexMax*100)+"%");
execCMD("dl "
+ "--exec \"move {} H:\\"
+folder+"\\{}\" http://**.******.com/ts/"
+indexMain+"/"
+indexSub+"/"
+folder+".m3u8."
+n+".ts");
}
System.out.println("下载结束! ");
}
3、创建文件夹
将下载的文件存入统一文件夹,作简单归档
//创建文件夹测试成功, 将下载的文件统一放进一个文件夹中
public static void createFolder(String folder) throws IOException{
File file = new File("H:\\"+folder);
if(!file.exists()){
file.mkdir();
System.out.println("文件夹"+folder+"创建成功");
}
}
4、执行
来源:数据架构师
//直接输入CMD命令测试
public static String execCMD(String command) {
StringBuilder sb =new StringBuilder();
try {
Process process=Runtime.getRuntime().exec(command);
BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while((line=bufferedReader.readLine())!=null)
{
sb.append(line+"\n");
}
} catch (Exception e) {
return e.toString();
}
return sb.toString();
}