jsoup有效文件路径抛出java。木卫一。FileNotFoundException
我有一个用Java下载的图片列表。这项工作:
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);
}
}
然而,我正在编写的程序的另一部分需要使用图像链接中已有的路径。因此,如果这是the link,我希望将图像保存为05785.gif
。所以我试了一下:
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);
}
}
但这带来了一个错误:
Exception in thread "main" java.io.FileNotFoundException: C:\Users\Ian\Homestuck\images\05785.gif
(The filename, directory name, or volume label syntax is incorrect)
即使这是一个有效的文件路径;我已经使用上面的第一个代码位保存了数百张其他图像。我怎样才能解决这个问题
# 1 楼答案
事实证明,问题在于尾随的换行符