|
|
@ -5,6 +5,7 @@ import java.net.HttpURLConnection; |
|
|
|
import java.net.MalformedURLException; |
|
|
|
import java.net.URL; |
|
|
|
import java.net.URLConnection; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
public class VideoTest { |
|
|
|
|
|
|
@ -30,7 +31,7 @@ public class VideoTest { |
|
|
|
//设置超时
|
|
|
|
httpURLConnection.setConnectTimeout(1000*5); |
|
|
|
//设置请求方式,默认是GET
|
|
|
|
httpURLConnection.setRequestMethod("POST"); |
|
|
|
httpURLConnection.setRequestMethod("GET"); |
|
|
|
// 设置字符编码
|
|
|
|
httpURLConnection.setRequestProperty("Charset", "UTF-8"); |
|
|
|
// 打开到此 URL引用的资源的通信链接(如果尚未建立这样的连接)。
|
|
|
@ -46,10 +47,10 @@ public class VideoTest { |
|
|
|
BufferedInputStream bin = new BufferedInputStream(httpURLConnection.getInputStream()); |
|
|
|
// 指定文件名称(有需求可以自定义)
|
|
|
|
|
|
|
|
String fileFullName=""; |
|
|
|
if(urlPath.contains("=")){ |
|
|
|
fileFullName=urlPath.substring(urlPath.lastIndexOf("=")+1); |
|
|
|
} |
|
|
|
String fileFullName=urlPath.substring(urlPath.lastIndexOf("/") + 1); |
|
|
|
// if(urlPath.contains("=")){
|
|
|
|
// fileFullName=urlPath.substring(urlPath.lastIndexOf("=")+1);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// 指定存放位置(有需求可以自定义)
|
|
|
|
String path = downloadDir + File.separatorChar + fileFullName; |
|
|
@ -58,6 +59,9 @@ public class VideoTest { |
|
|
|
if (!file.getParentFile().exists()) { |
|
|
|
file.getParentFile().mkdirs(); |
|
|
|
} |
|
|
|
if (!file.exists()) { |
|
|
|
file.createNewFile(); |
|
|
|
} |
|
|
|
|
|
|
|
OutputStream out = new FileOutputStream(file); |
|
|
|
int size = 0; |
|
|
@ -90,10 +94,26 @@ public class VideoTest { |
|
|
|
* 测试 |
|
|
|
* @param args |
|
|
|
*/ |
|
|
|
public static void main(String[] args) { |
|
|
|
public static void main(String[] args) throws Exception { |
|
|
|
|
|
|
|
// 指定资源地址,下载文件测试
|
|
|
|
downloadFile("http://1258473962.vod2.myqcloud.com/1e124671vodcq1258473962/76557f735285890810478037694/VCj25SXUgFsA.mp4", "D:/temp/"); |
|
|
|
// downloadFile("http://1258473962.vod2.myqcloud.com/1e124671vodcq1258473962/76557f735285890810478037694/VCj25SXUgFsA.mp4", "D:/temp/");
|
|
|
|
List<Object[]> objects = PoiUtil.readExce(new File("D:\\temp\\test.xlsx"), 0, null, 0, false); |
|
|
|
for (int i = 0; i < objects.size(); i++) { |
|
|
|
Object[] obj = objects.get(i); |
|
|
|
if (obj == null || obj.length < 3) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
String path = (String)obj[2]; |
|
|
|
String dir = "D:\\temp\\" + obj[0] + "\\" + obj[1]; |
|
|
|
try{ |
|
|
|
downloadFile(path, dir); |
|
|
|
} catch (Exception e) { |
|
|
|
System.out.println("下载失败:" + dir); |
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|