问题
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();
}
}
}
回答1:
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.
来源:https://stackoverflow.com/questions/19467172/unable-to-download-pdf-weblinks-using-org-apache-commons-io-java-library