java - 在 Java hdfs 中读取文件

标签 java linux hadoop solaris hdfs

我在集群上运行该程序时遇到了问题,因此决定在函数 map 和 reduce 中读取 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();

关于java - 在 Java hdfs 中读取文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13166123/

相关文章:

java - 简单 java 程序中的意外结果

java - 使用 apache camel 的 camel-kafka 组件手动提交消费者偏移量

Java Sax 树(重复属性)

linux - USSD 网关实现

c# - HDInsight SDK [用于Hadoop的Microsoft .NET SDK]

hadoop - 具有关系运算符条件的配置单元分区

java - Tuckey UrlRewrite 中的正则表达式

linux - 使用后台进程优化脚本以提高速度

linux - 嵌入式期望脚本返回 bash 成功或失败

python - Hadoop:用Python代码处理图像文件