I have a list of images I'm trying to download in Java. This works:
for (String i : link_array) {
File image = new File(outputFolderImages, image_id+".gif");
if (!image.exists()) {
System.out.println("Downloading: "+i+" to file "+image);
FileUtils.copyURLToFile(new URL(i), image, 10000, 10000);
}
}
However, a different part of the program I'm writing necessitates using the path already in the image link. So if if this is the link, I would want to save the image as 05785.gif
. So I tried this:
for (String i : link_array) {
String x = i.replace("http://www.mspaintadventures.com/storyfiles/hs2/","");
File image = new File(outputFolderImages, x);
if (!image.exists()) {
System.out.println("Downloading: "+i+" to file "+image);
FileUtils.copyURLToFile(new URL(i), image, 10000, 10000);
}
}
But this throws the error:
Exception in thread "main" java.io.FileNotFoundException: C:\Users\Ian\Homestuck\images\05785.gif
(The filename, directory name, or volume label syntax is incorrect)
Even though this is a valid file path; I've saved hundreds of other images uses the first code bit above. How can I fix this?
It turns out the issue was with trailing newlines.