本文介紹了爪哇.從 FTP 讀取文件,但不要全部下載的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我需要從 FTP 讀取 CSV 文件頭.
I need to read CSV file header from FTP.
由于這些文件可能非常大,我不需要下載它們.
As these files can be very huge, I don't need to download them.
有沒有辦法從 FTP 讀取 CSV 文件的第一行并中止連接?
Is there a way to read first line of CSV file from FTP and abort connection?
推薦答案
只讀取第一行,忽略剩余部分并關閉流.智能 FTP 客戶端在提供任何內容供讀取之前不會在內存中緩沖 整個 流.
Just read only the first line, ignore the remnant and close the stream. A smart FTP client won't buffer the entire stream in memory before providing anything for read.
假設您使用的是 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);
這篇關于爪哇.從 FTP 讀取文件,但不要全部下載的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!