При этом я посмотрел другие решения, и в принципе они у всех идентичны, в моем решении нет ничего принципиально нового, в чем ошибка?
package com.javarush.task.task31.task3112;
import java.io.*;
import java.net.URL;
import java.nio.file.*;
/*
Загрузчик файлов
*/
public class Solution {
public static void main(String[] args) throws IOException {
Path passwords = downloadFile("https://javarush.ru/testdata/secretPasswords.txt", Paths.get("D:/MyDownloads"));
for (String line : Files.readAllLines(passwords)) {
System.out.println(line);
}
}
public static Path downloadFile(String urlString, Path downloadDirectory) throws IOException {
URL url = new URL(urlString);
InputStream inputStream = url.openStream();
Path tempFile = Files.createTempFile("temp-",".tmp");
Files.copy(inputStream, tempFile);
Path newPath=new File(downloadDirectory.toString()+"/"+new File(urlString).getName()).toPath();
Files.move(tempFile,newPath);
return newPath;
}
}