簡體   English   中英

在Java HDFS中讀取文件

[英]Reading a file in Java hdfs

我在群集上運行程序時遇到問題,決定從功能映射和精簡中的hdfs文件讀取。 如何逐行讀取hdfs文件並刻錄以讀取ArrayList中的行?

只是一個演示代碼段:

Path path = new Path(filePath);
FileSystem fs = path.getFileSystem(context.getConfiguration()); // context of mapper or reducer
FSDataInputStream fdsis = fs.open(path);
BufferedReader br = new BufferedReader(new InputStreamReader(fdsis));
String line = "";
ArrayList<String> lines = new ArrayList<String>();
while ((line = br.readLine()) != null) {
    lines.add(line);
}
br.close();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM