2010-05-14 57 views

回答

12

只讀取第一行,忽略剩餘並關閉流。在提供任何需要讀取的內容之前,智能FTP客戶端不會緩衝內存中的整個流。

假設你正在使用Apache Commons NetFTPClient

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);