From 3ec86f6369b41ddc7a41b8ab121e9a75d77ec2d3 Mon Sep 17 00:00:00 2001 From: zhizhi wu <2377881365@qq.com> Date: Sat, 28 Nov 2020 11:26:26 +0800 Subject: [PATCH] =?UTF-8?q?video=20=E4=B8=8B=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/java/com/ccsens/util/VideoTest.java | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/util/src/test/java/com/ccsens/util/VideoTest.java b/util/src/test/java/com/ccsens/util/VideoTest.java index f2535fcc..09d212cc 100644 --- a/util/src/test/java/com/ccsens/util/VideoTest.java +++ b/util/src/test/java/com/ccsens/util/VideoTest.java @@ -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 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(); + + } + } } }