jayrlsw

Get image numbers

Feb 9th, 2016
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 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 getImage {
  8.    
  9.     public static void main (String args[]) throws IOException{
  10.         String url = "http://dummyimage.com/600x400/000/fff&text=";
  11.         String destination = "C:\\Users\\ruudi\\Desktop\\images\\num";
  12.        
  13.         for(int i = 0; i <= 1000000; i++){
  14.             saveImage(url, destination, i);
  15.             System.out.println("Done " + i);
  16.         }
  17.         System.out.println("COMPLETE");
  18.     }
  19.    
  20.     public static void saveImage(String imageUrl, String destination, int iter) throws IOException {
  21.         URL url = new URL(imageUrl + iter);
  22.         InputStream is = url.openStream();
  23.         OutputStream os = new FileOutputStream(destination + iter + ".png");
  24.        
  25.         byte[] b = new byte[2048];
  26.         int length;
  27.        
  28.         while((length = is.read(b)) != -1){
  29.             os.write(b, 0, length);
  30.         }
  31.        
  32.         is.close();
  33.         os.close();
  34.     }
  35.    
  36. }
Add Comment
Please, Sign In to add comment