Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. public void downloadVideo(String Video_URL) {
  2. try {
  3.  
  4. url = new URL(Video_URL);
  5. HttpURLConnection c = (HttpURLConnection) url.openConnection();
  6. c.setRequestMethod("GET");
  7. c.setDoOutput(true);
  8. c.connect();
  9. PATH = Environment.getExternalStorageDirectory()
  10. + "/urpath/";
  11.  
  12. Log.d("", "the path to store : " + PATH);
  13.  
  14. File file = new File(PATH);
  15. file.mkdirs();
  16.  
  17. File outputFile = new File(file, fileName);
  18. FileOutputStream fos = new FileOutputStream(outputFile);
  19. InputStream is = c.getInputStream();
  20. byte[] buffer = new byte[1024];
  21. int len1 = 0;
  22. while ((len1 = is.read(buffer)) != -1) {
  23. fos.write(buffer, 0, len1);
  24. }
  25. fos.close();
  26. is.close();
  27.  
  28. mHandler.sendEmptyMessage(DOWNLOADED_SUCCESS);
  29. } catch (Exception e) {
  30. mHandler.sendEmptyMessage(DOWNLOADED_FAILED);
  31. Log.d("TAG", " downloadVideo exception " + e.getMessage());
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement