title: How to download video file from url to sd card
body: <p>I am trying to download a video file from url in folder in sd card of real device not on emulator.Code is:</p>
  
  <pre><code>import java.io.BufferedInputStream;
  import java.io.File;
  import java.io.FileOutputStream;
  import java.net.URL;
  import java.net.URLConnection;
  import org.apache.http.util.ByteArrayBuffer;
  import android.app.Activity;
  import android.os.Bundle;
  import android.os.Environment;
  import android.util.Log;
  
  public class VideoDownload extends Activity {
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      File folder =  new File(Environment.getExternalStorageDirectory()+"/MyFolder");
      folder.mkdir();
      try{ 
  
      String fileName = Environment.getExternalStorageDirectory()+"/Myfolder";
  URL url = new URL("my url/song.mp4");
  File file = new File(fileName);
  URLConnection ucon = url.openConnection();
  InputStream is = ucon.getInputStream();
  BufferedInputStream bis = new BufferedInputStream(is);
  ByteArrayBuffer baf = new ByteArrayBuffer(50);
  int current = 0;
  while ((current = bis.read()) != -1) {
  baf.append((byte) current);
  }
  FileOutputStream fos = new FileOutputStream(file);
  fos.write(baf.toByteArray());
  fos.close();
      }
      catch(Exception e)
      {
      }
  
      }
      }
  </code></pre>
  
  <p>I am getting no any error but video file didn't download in folder. What am i doing wrong?
  Any hint? Thanks in advance.</p>