Python - getFile Internet


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  1. package get.file.example;
  2.  
  3. import java.io.BufferedInputStream;
  4. import java.io.FileOutputStream;
  5. import java.io.IOException;
  6. import java.net.MalformedURLException;
  7. import java.net.URL;
  8.  
  9. public class GetFileExample
  10. {
  11. public GetFileExample()
  12. {
  13. try
  14. {
  15. byte[] bite = new byte[2048];
  16. int read;
  17. URL url = new URL("http://switch.dl.sourceforge.net/sourceforge/pys60miniapps/FlickrS60_src_v0.1b.tar.bz2");
  18.  
  19. BufferedInputStream bis = new BufferedInputStream(url.openStream());
  20. FileOutputStream fos = new FileOutputStream("/tmp/file.tar.bz2");
  21.  
  22. while((read = bis.read(bite))>0)
  23. {
  24. fos.write(bite, 0, read);
  25. System.out.println("--");
  26. }
  27.  
  28. fos.close();
  29. bis.close();
  30.  
  31. System.out.println("FINE");
  32.  
  33. }
  34. catch(MalformedURLException e)
  35. {
  36. e.printStackTrace();
  37. }
  38. catch(IOException e)
  39. {
  40. e.printStackTrace();
  41. }
  42. }
  43.  
  44. public static void main(String[] args)
  45. {
  46. new GetFileExample();
  47. }
  48. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.