简体   繁体   English

无法使用org.apache.commons.io Java库下载pdf网站链接

[英]Unable to download pdf weblinks using org.apache.commons.io java library

I am trying to download PDF weblinks using org.apache.commons.io library java. 我正在尝试使用org.apache.commons.io库Java下载PDF网站链接。 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. 我想下载' https://----------------.pdf'intp pdf文件,当我按照java类运行时,它会在磁盘上创建目标pdf,但我无法打开或阅读该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. 如果有人会检查我的代码有什么问题以及如何将pdf网站链接下载到pdf文件,我将不胜感激。

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. 您需要将文件另存为pdf,而不是html。尝试将下载的文件重命名为kodejava.pdf并打开。 I am able to download it as .pdf and open it. 我可以将其下载为.pdf并打开。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM