[英]How to download/open PDF file on Windows using Java/FTP?
I am trying to download and open a PDF file from the server using the below code and the org.apache.commons.net.ftp.FTP client, but it doesn't work on Windows 8. It creates the pdf in a folder but it creates a corrupted file. 我正在尝试使用以下代码和org.apache.commons.net.ftp.FTP客户端从服务器下载并打开PDF文件,但在Windows 8上无法使用。它在文件夹中创建pdf,但是它创建了一个损坏的文件。 It works fine on the Mac. 在Mac上运行正常。 Any ideas what I can do in order fix this? 有什么想法可以解决这个问题吗? Thanks 谢谢
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");
}
}
}
Here is a example using org.apache.commons.net.ftp.FTP to download a file 这是使用org.apache.commons.net.ftp.FTP下载文件的示例
Maybe this works for you. 也许这对你有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.