File downloader

  • 14
  • Locked
Implement a downloadFile(String urlString, Path downloadDirectory) method whose inputs are a URL to a file to be downloaded and the destination folder for the download. The method must create a URL object and download the file's contents to the local disk. Download it to a temporary directory first so that if the download fails, there won't be partially downloaded files in your directory.
You can't complete this task, because you're not signed in.
Comments (4)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Олег Байбула
Level 32 , Ukraine
Expert
10 March, 14:23
The task tells: "Only use classes and methods from the java.nio package." The correct solution uses: java.io.InputStream; I tried to break my brain not to use java.io.InputStream; It is definitely zero star exersize.
Skynet
Level 40 , USA
21 June 2021, 19:35
Hint: to get the file name from the given urlString, you can use: urlString.substring(urlString.lastIndexOf("/"));
Justin Smith
Level 38 , Greenfield, USA, United States
4 August 2022, 13:40
Also an important thing I learned the hard way in this task: The method String URL.getFile() does not do what you might think it does. I tried that and struggled for a long time with it. Also, your code doesn't validate. I tried using it, and after if failed to validate, I changed only that line to the official solution line, and it passed. I think... shouldn't it be urlString.substring(urlString.lastIndexOf("/") + 1)?
Andrei
Level 41
15 June 2021, 12:47
I liked this exercise, it was difficult but manageable.