1

我在集群上运行程序时遇到问题,并决定在函数 map 和 reduce 中读取 hdfs 文件。如何逐行读取hdfs文件并刻录读取ArrayList中的行?

4

1 回答 1

1

只是一个演示代码片段:</p>

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();
于 2012-11-01T04:49:49.483 回答