Chiddix

beast dumper

Feb 18th, 2013
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.15 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.BufferedWriter;
  3. import java.io.FileWriter;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.net.URL;
  7. import java.net.URLConnection;
  8.  
  9.  
  10. public class Dumper {
  11.  
  12.     public static final String IN = "http://services.runescape.com/m=itemdb_rs/bestiary/beastData.json?beastid=";
  13.     public static final String OUT = "beasts.txt";
  14.    
  15.     public static void main (String[] args) {
  16.         try {
  17.             dump(IN, OUT);
  18.         } catch (IOException e) {
  19.             e.printStackTrace();
  20.         }
  21.     }
  22.    
  23.     public static void dump(String in, String out) throws IOException {
  24.         BufferedWriter writer = new BufferedWriter(new FileWriter(out));
  25.        
  26.         URL url;
  27.         URLConnection connection;
  28.         BufferedReader reader;
  29.         String page;
  30.        
  31.         for (int i = 1; i < Integer.MAX_VALUE; i++) {
  32.             url = new URL(in + i);
  33.             connection = url.openConnection();
  34.             reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
  35.             page = reader.readLine();
  36.            
  37.             if (page == null) {
  38.                 continue;
  39.             }
  40.            
  41.             System.out.println(page);
  42.             writer.write(page);
  43.             writer.newLine();
  44.             writer.flush();
  45.         }
  46.         writer.close();
  47.     }
  48. }
Add Comment
Please, Sign In to add comment