2012-10-01 28 views
1

我使用apache ftp客戶端下載文本文件。我的問題是,當我檢索文件時,我總是在文件末尾找到新的一行。這是我的代碼:apache ftp客戶端在文件末尾添加新行,同時檢索文件

String value = new String(output.toByteArray(), "UTF-8"); 

誰能幫助我:

FTPClient ftpClient = new FTPClient(); 

    ftpClient.connect(ftpServer); 
    ftpClient.login(ftpUser, ftpPassword); 

    log.info("Connected to server " + ftpServer + "."); 
    log.info(ftpClient.getReplyString()); 

    int reply = ftpClient.getReplyCode(); 

    if (!FTPReply.isPositiveCompletion(reply)) { 
     ftpClient.disconnect(); 
     throw new Exception("error"); 
    } 

    ftpClient.enterLocalPassiveMode(); 

    ByteArrayOutputStream output = new ByteArrayOutputStream(); 

    boolean result = ftpClient.retrieveFile(fileName, output); 

    output.close(); 

    ftpClient.logout(); 

    if (ftpClient.isConnected()) { 
     try { 
      ftpClient.disconnect(); 
     } catch (IOException ioe) { 
      // do nothing 
     } 
    } 

    log.info("Disconnected from " + ftpServer + "."); 

後來我讀使用文件? 謝謝

回答

4

讓我們試試吧: ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE); 它有幫助。