最佳答案
只读第一行,忽略残余并关闭流.在提供任何要读取的内容之前,智能FTP客户端不会将整个流缓冲在内存中.
假设您正在使用Apache Commons Net FTPClient:
BufferedReader reader = null;
String firstLine = null;
try {
InputStream stream = ftpClient.retrieveFileStream(ftpFile.getName());
reader = new BufferedReader(new InputStreamReader(stream,"UTF-8"));
firstLine = reader.readLine();
} finally {
if (reader != null) try { reader.close(); } catch (IOException logorIgnore) {}
}
doYourThingWith(firstLine);