示例#1
0
 // This makes a JSON file that is a list of JSONObjects
 public static void makeJSONSLISTFILE(String file_path, ArrayList<JSONObject> jsons) {
   MakeFile(file_path);
   AddToFile(file_path, "[");
   if (jsons.size() > 0) {
     int i;
     for (i = 0; i < jsons.size() - 1; i++) {
       AddToFile(file_path, jsons.get(i).toString());
       AddToFile(file_path, ",");
     }
     AddToFile(file_path, jsons.get(i).toString());
   }
   AddToFile(file_path, "]");
 }
示例#2
0
 // Like URLtoList except it downloads new pages to the directory(which DOES NOT include the
 // filename).
 // It will check the directory to see if the page has already been downloaded and read from that
 // instead of downloading the same page over and over.
 // This already generates the filename for SEREBII. filename is NOT passed in
 public static ArrayList<String> URLtoListCACHE(String dir, String link) {
   String dex = getLastSub(link, "pokedex", null);
   // this part generates the filename based on the link
   dex = dex.replace("-", "");
   dex = dex.replace("/", "");
   dex = dex.replace("shtml", "html");
   String filename = dex;
   String l = filename;
   l = getSub(l, null, ".");
   String file_directory =
       dir + l + "TEMP.html"; // using a temp name to tell if file is partially downloaded.
   String good_name = file_directory.replace("TEMP.html", ".html");
   File finished = new File(good_name);
   File f = new File(file_directory);
   if (!finished.exists()) {
     MakeFile(file_directory);
     ArrayList<String> lines = URLtoList(link);
     for (String s : lines) {
       AddToFile(file_directory, s);
     }
     // marking it as done, not corrupt
     f.renameTo(new File(good_name));
     return lines;
   }
   // File already downloaded, read from there
   return FiletoStringList(good_name);
 }
示例#3
0
 // This makes a JSON file made up of a single JSONObject
 public static void makeJSONFILE(String file_path, JSONObject json) {
   try {
     MakeFile(file_path);
     AddToFile(file_path, json.toString(4));
   } catch (Exception e) {
     e.printStackTrace();
     System.exit(0);
   }
 }