Все копирует по условию, но не принимает валидатор
package com.javarush.task.task31.task3112;
import java.io.File;
import java.io.IOException;
import java.net.Proxy;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
/*
Загрузчик файлов
*/
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);
Path ps = Paths.get(url.getPath());
Path tempFile = Files.createTempFile("test",".tmp");
Files.copy(url.openStream(),tempFile, StandardCopyOption.REPLACE_EXISTING);
Path res;
if (!Files.exists(downloadDirectory))
{
Files.createDirectories(downloadDirectory);
}
res = Paths.get(downloadDirectory.toAbsolutePath().toString()+"\\"+ps.getFileName());
return Files.move(tempFile,res,StandardCopyOption.REPLACE_EXISTING);
// implement this method
}
}