Advertisement
Guest User

Untitled

a guest
May 24th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. import java.io.FileOutputStream;
  2. import java.io.IOException;
  3. import java.io.InputStream;
  4. import java.io.OutputStream;
  5. import java.net.URL;
  6.  
  7. public class SaveImage {
  8.  
  9. public static void main(String[] args) throws Exception {
  10. String imageUrl = "http://гувм.мвд.рф/media/fms/img/logo.png";
  11. String destinationFile = "d:\image.jpg";
  12.  
  13. saveImage(imageUrl, destinationFile);
  14. }
  15.  
  16. public static void saveImage(String imageUrl, String destinationFile) throws IOException {
  17. URL url = new URL(imageUrl);
  18. InputStream is = url.openStream();
  19. OutputStream os = new FileOutputStream(destinationFile);
  20.  
  21. byte[] b = new byte[2048];
  22. int length;
  23.  
  24. while ((length = is.read(b)) != -1) {
  25. os.write(b, 0, length);
  26. }
  27.  
  28. is.close();
  29. os.close();
  30. }
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement