解析网络视频地址保存视频到本地

package com.chint.tpaas.course.utils;

import ws.schild.jave.MultimediaInfo;
import ws.schild.jave.MultimediaObject;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;


import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import sun.net.www.protocol.http.HttpURLConnection;


import java.io.*;

public class VideoLocalUtil {
public static void main(String[] args) throws IOException {
save("https://XXXX/sites/Resources/Documents/20201215095518_波峰焊接知识培训.mp4","G:\\Temp\\test1.mp4");
}
public static void save(String path, String fileName) throws IOException {
try {
path = EncodUtil.encodeURLChinese(path);
URL url = new URL(path);
OutputStream out = new FileOutputStream(new File(fileName));
InputStream input = url.openStream();
BufferedInputStream bis = new BufferedInputStream(input);
byte[] buf = new byte[1024 * 2048];
int temp = 0;
while ((temp = bis.read(buf)) != -1) {
out.write(buf, 0, temp);
}
bis.close();
out.close();
}catch (IOException e){
e.printStackTrace();
}

}
}

posted @ 2020-12-16 10:09  gykuang  阅读(449)  评论(0编辑  收藏  举报