无法下载PDF网站链接使用org.apache.commons.io Java库 [英] Unable to download pdf weblinks using org.apache.commons.io java library
问题描述
我想下载PDF使用网页链接库org.apache.commons.io java的。
我想下载 https://开头-------- -------- PDF INTP pdf文件,当我运行下面的java类它创建我的磁盘上的目标PDF格式,但我无法打开或读取PDF格式。它抛出一个错误文件损坏或无法读取。
我想AP preciate如果有人将检查什么是错在我的code和如何下载PDF网站链接到PDF文件。
进口的java.io.File;
进口java.io.IOException异常;
进口的java.net.URL;进口org.apache.commons.io.FileUtils;公共类简单{
公共静态无效的主要(字串[] args){
尝试{
网址URL =新的URL(https://docs.google.com/**********.pdf);
文件目的地=新的文件(kodejava.html); //
//复制从URL到目标文件的字节。
//
FileUtils.copyURLToFile(URL,目的地);
}赶上(IOException异常五){
e.printStackTrace();
}
}
}
您需要将您的文件保存为PDF文件,而不是html.Try重命名下载的文件作为kodejava.pdf和开放。我能下载为.pdf和打开它。
I am trying to download PDF weblinks using org.apache.commons.io library java. I want download 'https://----------------.pdf' intp pdf file, when I run following java class it creates the destination pdf on my disk but I am unable to open or read that pdf. It throws an error file is corrupted or unable to read.
I would appreciate if somebody will check whats wrong in my code and how to download pdf weblinks in to pdf file.
import java.io.File;
import java.io.IOException;
import java.net.URL;
import org.apache.commons.io.FileUtils;
public class Simple {
public static void main(String[] args) {
try {
URL url = new URL("https://docs.google.com/**********.pdf");
File destination = new File("kodejava.html");
//
// Copy bytes from the URL to the destination file.
//
FileUtils.copyURLToFile(url, destination);
} catch (IOException e) {
e.printStackTrace();
}
}
}
You need to save your file as a pdf, not an html.Try renaming the downloaded file as kodejava.pdf and open. I am able to download it as .pdf and open it.
这篇关于无法下载PDF网站链接使用org.apache.commons.io Java库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!