@Override protected String doInBackground(String... sUrl) { File folders = new File(Environment.getExternalStorageDirectory() + "/pathofthefile/"); folders.mkdirs(); File file; file = new File( Environment.getExternalStorageDirectory() + "/pathofthefile/" + FirstSettings_two.file_video); if (!file.exists()) { try { file.createNewFile(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { file.delete(); try { file.createNewFile(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } try { URL url = new URL(sUrl[0]); URLConnection connection = url.openConnection(); connection.connect(); // this will be useful so that you can show a typical 0-100% // progress bar int fileLength = connection.getContentLength(); // download the file InputStream input = new BufferedInputStream(url.openStream()); OutputStream output = new FileOutputStream(file); byte data[] = new byte[1024]; long total = 0; int count; while ((count = input.read(data)) != -1) { total += count; // publishing the progress.... publishProgress((int) (total * 100 / fileLength)); output.write(data, 0, count); } output.flush(); output.close(); input.close(); return "Downloaded"; } catch (Exception e) { // Toast.makeText(context, // "exeption",Toast.LENGTH_LONG).show(); return null; } }