Recently, I wanted to put my favorite MV on my personal site, but the Mac client and the web version of netease Cloud even have no download button! Well, it’s time to do it yourself… Rich and well fed, the web page can play out of the affirmation is to get, the most magical and the most stable way of course is to open the screen recording software. But this time in order to play the effect, can not use the lowest end of the way as far as possible!
I haven’t written about IO for a long time, so here’s an example to practice:
All we need to get is the HTTP request link and the request header:
Public static void main(String[] args) throws Exception{// Enter the video address String URL = "https://vodkgeyttp8.vod.126.net/cloudmusic/MCQ4IjAxICAwICEhICAgIQ==/294001/672888e4902fac1298f8e984182690c7.mp4?wsSecre t=809e59d2b289d82917dedef9c05c64b2&wsTime=1556853453"; File file = new File("/Users/tim/Desktop/a"+".mp4"); // create file if(! File.createnewfile ()) throw new RuntimeException(" file creation failed "); HttpURLConnection con; FileOutputStream fs = null; InputStream is; BufferedInputStream bs = null; try { con = (HttpURLConnection) new URL(url).openConnection(); Con. SetRequestProperty (" the user-agent ", "Mozilla / 5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36"); // Input stream is = con.getinputStream (); bs = new BufferedInputStream(is); fs = new FileOutputStream(file); byte[] bytes = new byte[1024 * 10]; int line ; while((line = bs.read(bytes))! = -1){ fs.write(bytes, 0, line); fs.flush(); } } catch (Exception e) { e.printStackTrace(); } finally{ if(fs! = null){ try { fs.close(); } catch (IOException e) { e.printStackTrace(); } } if(bs! =null){ try { bs.close(); } catch (IOException e) { e.printStackTrace(); }}}}Copy the code
Well, home page MV is so complete download, so want to download MV is so simple!