gpt4 book ai didi

java - 如何使用 Java/FTP 在 Windows 上下载/打开 PDF 文件?

转载 作者:太空宇宙 更新时间:2023-11-04 13:54:35 24 4
gpt4 key购买 nike

我正在尝试使用以下代码和 org.apache.commons.net.ftp.FTP 客户端从服务器下载并打开 PDF 文件,但它在 Windows 8 上不起作用。它会在文件夹中创建 pdf,但会创建损坏的文件。它在 Mac 上运行良好。有什么想法我可以做些什么来解决这个问题吗?谢谢

   private static void openFileFTP(String fileName) throws  FileNotFoundException, 
IOException {

ftpClient = new FTPClient();
if (checkConnection()) {

//Set the type of file to be displayed
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);

FileOutputStream outPutFile = new FileOutputStream(fileName);
ftpClient.retrieveFile(serverDirectory + fileName, outPutFile);

File file = new File(fileName);

try {
Desktop.getDesktop().open(file);
} catch (IOException ioe) {
System.out.println(ioe + "error here");
}
}
}

最佳答案

这是使用 org.apache.commons.net.ftp.FTP 下载文件的示例

也许这对你有用。

关于java - 如何使用 Java/FTP 在 Windows 上下载/打开 PDF 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29967226/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com