public static int MAXID = 4000;
public static void main(String[] args) throws IOException {
Path backupDir = Paths.get("./backup/");
if (!Files.exists(backupDir)) {
Files.createDirectory(backupDir);
}
for (int i = 0; i < MAXID; i++) {
download(backupDir.toString(), i);
}
}
public static void download(String dir, int id) throws IOException {
String baseURL = "http://forum.mcmodding.ru/viewtopic.php?id=";
URL url = new URL(baseURL + id);
Path file = Paths.get(dir, id + ".html");
Files.createFile(file);
StringBuilder sb = new StringBuilder();
try (OutputStream out = new BufferedOutputStream(Files.newOutputStream(file, CREATE)); BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()))) {
String inputLine;
while ((inputLine = in.readLine()) != null) {
sb.append(inputLine);
}
} catch (IOException x) {
System.err.println(x);
}
Files.write(file, sb.toString().getBytes());
System.out.println("Download complete from: " + baseURL + id);
}