【发布时间】:2014-12-10 16:14:11
【问题描述】:
我正在尝试将以下网址下载为本地文件夹中的 pdf 文件。
http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=1498781&tag=1
到目前为止我尝试过的是:
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
public class DownloadPDF {
public DownloadPDF () {}
public static String download (String link, String i) {
String save = null;
try{
String file = link;
URL url = new URL(file);
InputStream in = url.openStream();
save = "local_folder/name.pdf";
FileOutputStream fos = new FileOutputStream(new File(save));
int length = -1;
byte[] buffer = new byte[1024];
while ((length = in.read(buffer)) > -1) {
fos.write(buffer, 0, length);
}
fos.close();
in.close();
System.out.println("file is downloaded");
} catch (IOException e) {
e.printStackTrace();
}
return save;
}
}
这适用于:
http://ongambling.org/wp-content/uploads/2011/02/binde-2005-jgs-postprint.pdf
但不适用于上面给出的第一个网址?还有其他建议吗?
【问题讨论】:
-
你希望从 link1 下载什么 ?a pdf
-
@getlost 我想从link1下载并保存为pdf