Downaload a file programatically on android
<p>i am downloading files from web server programatically. after download is complete, i checked the file.the size ,extension and all other parameters are correct but i when i try to play that file in media player it is showing that it is corrupt.</p>

<p>plz help..</p>

<p>code:</p>

<pre><code>    byte[] b = null;
    InputStream in = null;
    b = new byte[Integer.parseInt(size)];    // size of the file.
    in = OpenHttpConnection(URL);            
    in.read(b);
    in.close();

    File folder = new File("/sdcard", "folder");
   boolean check = folder.mkdirs();

   Log.d("HttpDownload", "check " + check);

   File myFile = new File("/sdcard/folder/" + name);


    myFile.createNewFile();
   OutputStream filoutputStream = new FileOutputStream(myFile);

   filoutputStream.write(b);

   filoutputStream.flush();

   filoutputStream.close();
</code></pre>
