I need to download a video in the given link and save to my local directory. This is the code I used for that. And I'm using java nio package.
public void usingNio() throws Exception {
ReadableByteChannel readChannel = Channels.newChannel(new URL("https://www.dailymotion.com/embed/video/x82n558").openStream());
FileOutputStream fileOS = new FileOutputStream(newFile("C:\\Users\\Tecman\\Desktop\\Knowladge\\video.mp4"));
FileChannel writeChannel = fileOS.getChannel(); writeChannel.transferFrom(readChannel, 0, Long.MAX_VALUE);
}
Above code saving video.mp4 file in the given directory but it can't play using a video player. Seems like video file is corrupted.
I have tried several example in the internet but no luck. I know there are tons of video downloading tools available in internet but my purpose is download a video file from any provided link and save it to the directory using java. What i'm doing wrong here any guidance, code segment, link or tip will be really helpful.