title: Cannot download video file with android emulator
body: <p>Here's the code to download a 3pg video file. Maybe one can give me an idea about what's wrong with it. I really need help. Can't get it to download the file: </p>
  
  <blockquote>
    <p>Blockquote</p>
  </blockquote>
  
  <pre><code>        protected String doInBackground(String... sUrl) {
              byte[] data = new byte[1024];
              int count = 0;
              FileOutputStream fos = null;
              BufferedOutputStream output = null;
              try {
              URL url= new URL(sUrl[0]);
              URLConnection connection = url.openConnection();
              connection.connect();
              Log.v("URL"," " + connection.getURL());
              Log.v("File ", "length = " + connection.getContentLength());
              // download the file
              BufferedInputStream input = new BufferedInputStream(connection.getInputStream());
              File f = new File(Environment.getExternalStorageDirectory().getPath() + "/twokids.3gp");
              f.setWritable(true,true);
              try {
                  fos = new FileOutputStream(f);
                  } catch (FileNotFoundException fnfe) {
                      fnfe.getStackTrace();
                  } catch (SecurityException se) {
                      se.getStackTrace();
                  }
  
                  output = new BufferedOutputStream(fos);                                                                                                                        
  
              while ((count = input.read(data)) != -1) {
                  Log.v("Count="," " + count);
                  output.write(data, 0, count);
              }
              output.flush();
              output.close();
              input.close();
              Log.v("Download","Finished");
              } catch (IndexOutOfBoundsException iobe) {
              iobe.getStackTrace();
              } catch (IOException ioe) {
              ioe.getStackTrace();
              } catch (NullPointerException npe) {
              npe.getStackTrace();
              }
              catch (Exception e) {
              e.getStackTrace();
              }
  
          return null;
      }
  </code></pre>
  
  <p>And strangely enough, <em>sometimes</em> the method connection.getContentLength() returns -1 instead of the file length.</p>