title: How to download video from URL?
body: <p>I am trying to download a video file from URL.
  Below is my Code.</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          ProgressBack PB = new ProgressBack();
          PB.execute("");
      }
  
      private class ProgressBack extends AsyncTask&lt;String, String, String&gt; {
          ProgressDialog PD;
  
          @Override
          protected void onPreExecute() {
              PD = ProgressDialog.show(MainActivity.this, null, "Please Wait ...", true);
              PD.setCancelable(true);
          }
  
          @Override
          protected String doInBackground(String... arg0) {
              downloadFile("https://r8---sn-nhpax-ua8z.googlevideo.com/videoplayback?c=web&amp;clen=17641691&amp;cpn=Mf_hDzzzBYPH8N_J&amp;cver=as3&amp;dur=189.857&amp;expire=1425270280&amp;fexp=905657%2C907263%2C912333%2C926419%2C927622%2C931358%2C934947%2C936928%2C9406255%2C9406746%2C9406850%2C943917%2C945093%2C947225%2C947240%2C948124%2C951703%2C952302%2C952605%2C952612%2C952620%2C952901%2C955301%2C957201%2C959701&amp;gcr=il&amp;gir=yes&amp;id=o-AM54E58Im9m8yqaerEsKkGXOx0IWge8YN4h6OhFkcDTe&amp;initcwndbps=1488750&amp;ip=84.228.53.86&amp;ipbits=0&amp;itag=135&amp;keepalive=yes&amp;key=yt5&amp;lmt=1402678222642477&amp;mime=video%2Fmp4&amp;mm=31&amp;ms=au&amp;mt=1425248654&amp;mv=m&amp;pl=20&amp;ratebypass=yes&amp;requiressl=yes&amp;signature=E8027BCB4C1EE76254FC008B0044655E58485D81.931863F3A7AD6C6B01262BCD723B37E5396D4317&amp;source=youtube&amp;sparams=clen%2Cdur%2Cgcr%2Cgir%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Ckeepalive%2Clmt%2Cmime%2Cmm%2Cms%2Cmv%2Cpl%2Crequiressl%2Csource%2Cupn%2Cexpire&amp;sver=3&amp;upn=moGJHdfD4Z8", "Sample.mp4");
  
              return null;
          }
  
          protected void onPostExecute(Boolean result) {
              PD.dismiss();
  
          }
  
      }
  
  
      private void downloadFile(String fileURL, String fileName) {
          try {
              String rootDir = Environment.getExternalStorageDirectory()
                      + File.separator + "Video";
              File rootFile = new File(rootDir);
              rootFile.mkdir();
              URL url = new URL(fileURL);
              HttpURLConnection c = (HttpURLConnection) url.openConnection();
              c.setRequestMethod("GET");
              c.setDoOutput(true);
              c.connect();
              FileOutputStream f = new FileOutputStream(new File(rootFile,
                      fileName));
              InputStream in = c.getInputStream();
              byte[] buffer = new byte[1024];
              int len1 = 0;
              while ((len1 = in.read(buffer)) &gt; 0) {
                  f.write(buffer, 0, len1);
              }
              f.close();
          } catch (IOException e) {
              Log.d("Error....", e.toString());
          }
      }
  }
  </code></pre>
  
  <p>But it is not downloading. and it is showing <strong>java.io.FileNotFoundException</strong>.
  Is there any other way to download video file or anything wrong in my code.
  Can someone please help me?</p>