简体   繁体   English

从FTP服务器读取单行而无需使用它下载整个文件。sauronsoftware.ftp4j.FTPClient

[英]Read single line from FTP server without downloading whole file using it.sauronsoftware.ftp4j.FTPClient

How can we read single line from FTP server without downloading whole file using it.sauronsoftware.ftp4j.FTPClient. 我们如何从FTP服务器读取单行而不使用it.sauronsoftware.ftp4j.FTPClient.下载整个文件it.sauronsoftware.ftp4j.FTPClient.

Now, I am downloading whole file and than reading first line of file, is there any way we can read first line of file without download file in local machine. 现在,我正在下载整个文件,而不是读取文件的第一行,有什么方法可以读取文件的第一行而无需在本地计算机上下载文件。 It should use only it.sauronsoftware.ftp4j 它应该只使用它。sauronsoftware.ftp4j

@ http://www.sauronsoftware.it/projects/ftp4j/manual.php @ http://www.sauronsoftware.it/projects/ftp4j/manual.php

NOTE : It should use it.sauronsoftware.ftp4j.FTPClient and not apache . 注意:它应该使用it.sauronsoftware.ftp4j.FTPClient而不是apache

Mohit, 莫希特

Use the Socket dtConnection; 使用Socket dtConnection; dtConnection.getInputStream(); dtConnection.getInputStream(); of ftp4j.FTPClient you will get InputStream, Using that InputStream you can read first line of. 您将获得ftp4j.FTPClient的InputStream,使用该InputStream可以读取其中的第一行。

you can find below Example hoe to read first line using InputStream 您可以在下面的示例hoe中使用InputStream读取第一行

BufferedReader bufferedReader = null; BufferedReader bufferedReader = null; String firstLine = null; 字符串firstLine = null;

bufferedReader = new BufferedReader(new InputStreamReader(this.dataTransferInputStream, "UTF-8")); bufferedReader = new BufferedReader(new InputStreamReader(this.dataTransferInputStream,“ UTF-8”)); firstLine = bufferedReader.readLine(); firstLine = bufferedReader.readLine();

Hope this solution will work for you. 希望此解决方案对您有用。

You could make your own stream class that throws an exception after it has the first line written to it. 您可以使自己的流类在写入第一行之后引发异常。

Edit: or it could call abortCurrentDataTransfer() after it received the first line. 编辑:或者在收到第一行后可以调用abortCurrentDataTransfer()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM