Apache FTP客户端在检索文件时在文件末尾添加新行



我正在使用apache ftp客户端下载文本文件。我的问题是,当我检索文件时,我总是在文件末尾找到一个新行。这是我的代码:

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

后来我使用以下方法读取文件:

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

谁能帮我?谢谢

让我们试试: ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);它有帮助。

最新更新