Could someone please tell me what is wrong in the below code, I'm trying to merge two different video URLs to same file, (both videos have the same size 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();
}
I have tried to save the file using the above two methods but both create only one video file i.e., the second video is not appended (i'm able to save both files if given different names)