how to download streaming video

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rocky2588
    New Member
    • Jan 2015
    • 1

    how to download streaming video

    Any possible way to make a application streaming video downloader like youtube downloader .

    i googled and tried the code 100 kb file stored and stopped then not properly downloaded.

    Code:
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
     
    // decode the url     
    String result = java.net.URLDecoder.decode(enurl.getText(), "UTF-8");
    
     URL u = null;
    InputStream is = null;  
    
         try {
                  u = new URL(result);
                  is = u.openStream(); 
                  HttpURLConnection huc = (HttpURLConnection)u.openConnection();//to know the size of video
                  int size = huc.getContentLength();                 
    
              if(huc != null){
                  String fileName = "FILE.mp4";
                  String storagePath="F:/";
                      
                  File f = new File(storagePath,fileName);
    
                  FileOutputStream fos = new FileOutputStream(f);
                  byte[] buffer = new byte[1024];
                  int len1 = 0;
                  if(is != null){
                     while ((len1 = is.read(buffer)) > 0) {
                           fos.write(buffer,0, len1);   
                     }
                  }
                  if(fos != null){
                     fos.close();
                  }
              }                     
         }catch (MalformedURLException mue) {
                mue.printStackTrace();
         } catch (IOException ioe) {
                ioe.printStackTrace();
        } finally {
                   try {                
                     if(is != null){
                       is.close();
                     }
                   }catch (IOException ioe) {
                         
                   }
        }
        }
    Last edited by Rabbit; Jan 13 '15, 04:38 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
Working...