Анти

CumingSoon

Местный стендапер
1,634
12
269
Короче вот фигня, которая выкачает все темы в папку. Да я знаю, что это неправильно
Код:
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);
    }
 
2,955
12
А я говорил, что не забросил. Дракона же слушать не надо.
 
586
1
2
Ясно...Ник13... станет больше в 3 раза
[merge_posts_bbcode]Добавлено: 03.11.2015 17:18:13[/merge_posts_bbcode]

Тогда может и учебник запилите заодно ?)))
 
Сверху