2015-04-30 151 views
0

我想下載並使用下面的代碼和org.apache.commons.net.ftp.FTP客戶端從服務器打開PDF文件,但它不能在Windows 8上工作。它創建PDF文件夾,但它會創建一個損壞的文件。它在Mac上正常工作。任何想法我可以做什麼來解決這個問題?由於如何使用Java/FTP在Windows上下載/打開PDF文件?

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"); 
      } 
     } 
} 
+0

你使用什麼樣的庫進行ftp傳輸?也許嘗試關閉FileOutputStream。 – NaN

+0

我正在使用以下庫:org.apache.commons.net.ftp.FTP; org.apache.commons.net.ftp.FTPClient; – Bob

回答

相關問題