public static boolean DownloadFromUrl(String targetUrl,File file){
  try {
    URL url=new URL(targetUrl);
    Log.d(LOG_TAG,"Download begining");
    Log.d(LOG_TAG,"Download url:" + url);
    Log.d(LOG_TAG,"Downloaded file name:" + file.getAbsolutePath());
    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 (  IOException e) {
    Log.d(LOG_TAG,"Failed to download file with error: " + e);
    return false;
  }
  return true;
}

public static boolean DownloadFromUrl ( String targetUrl , File file ) { try { URL url = new URL ( targetUrl ) ; Log . d ( LOG_TAG , "Download begining" ) ; Log . d ( LOG_TAG , "Download url:" + url ) ; Log . d ( LOG_TAG , "Downloaded file name:" + file . getAbsolutePath ( ) ) ; 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 ( IOException e ) { Log . d ( LOG_TAG , "Failed to download file with error: " + e ) ; return false ; } return true ; }
download a given file from a target url to a given destination file .
