Видимо у меня проблемы с пониманием условий но я не вижу что из пунктов я не выполнил, все проверил
package com.javarush.task.task31.task3112;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.*;
import java.util.Comparator;
/*
Загрузчик файлов
*/
public class Solution {
public static void main(String[] args) throws IOException {
Path passwords = downloadFile("https://javarush.ru/testdata/secretPasswords.txt", Paths.get("C:/1"));
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);
//итоговый файл
Path newPath;
//пункт условия "Выкачивай сначала во временную директорию"
Path tempDir = Files.createTempDirectory(null);
Path tempFile = Files.createTempFile(tempDir, null, ".txt");
try (InputStream inputStream = url.openStream()) {
//копируем из потока во временный файл
Files.copy(inputStream, tempFile , StandardCopyOption.REPLACE_EXISTING);
//имя из ссылки
String fileName1 = Paths.get(url.getPath()).getFileName().toString();
newPath = downloadDirectory.resolve(fileName1);
//копируем
Files.move(tempFile, newPath, StandardCopyOption.REPLACE_EXISTING);
}
return newPath;
}
}