【发布时间】:2019-12-18 19:58:21
【问题描述】:
谁能告诉我下面的代码有什么问题,我正在尝试将两个不同的视频 URL 合并到同一个文件中,(两个视频的大小相同 1024x720)
String url1 = "https://test.com/vid1";
String url2 = "https://test.com/vid2";
FileOutputStream out = new FileOutputStream(new File("test.mp4"));
writeToFile(url1, out);
writeToFile(url2, out);
out.close();
//Even tried the below way of first saving one file and then opening the same file to append the stream data
/*
FileOutputStream out = new FileOutputStream(new File("test.mp4"));
writeToFile(url1, out);
out.close();
out = new FileOutputStream(new File("test.mp4"), true);
writeToFile(url2, out);
out.close();
*/
void writeToFile(String url, FileOutputStream out) {
HttpsURLConnection con = (HttpsURLConnection) new URL(url).openConnection();
con.setRequestMethod("GET");
BufferedInputStream bis = new BufferedInputStream(con.getInputStream());
int count;
byte buf[] = new byte[20480];
while((count = bis.read(buf, 0, 20480)) != -1)
out.write(buf, 0, count);
bis.close();
con.disconnect();
}
我尝试使用上述两种方法保存文件,但都只创建一个视频文件,即不附加第二个视频(如果给定不同的名称,我可以保存两个文件)
【问题讨论】:
-
我认为你正在反对标题 - “只创建一个视频”意味着你只播放一个视频 - 如果你提供一个完整的程序,我可能会回答
标签: java inputstream bufferedinputstream