java - MapReduce 跳过输入文件的第一行

标签 java mapreduce

有人知道如何在 MapReduce 中跳过输入文本文件的第一行吗?例如,我有以下输入文件:

Student Score
00001   90
00002   95
00003   90
      .
      .
      .

现在,我想统计每个分数的频率。但我必须跳过第一行,即标题(学生,分数),对吗?我怎样才能做到这一点?相反,如果我想在MapReduce(Score、Frequency)的输出文件中添加标题行,我该怎么做?提前致谢!

最佳答案

import java.util.Scanner;
import java.io.*; 
public class MyNameSpace{

public static void main(String[] args)
{
    try
    {
        Scanner c=new Scanner(new FileInputStream("filepath"));
        c.nextLine();//this gets the next line, since not assigning it to anything it just skips , if you want it, assign it to a string and use it
        //now read what you want to read
        c.close();
    }
    catch(FileNotFoundException e)
    {
        //process exception here
    }
}

}

无论如何,我希望在谷歌上可以找到您问题的许多答案,因此在此处提问之前请先进行大量搜索。

关于java - MapReduce 跳过输入文件的第一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27574999/

相关文章:

java - JVM内存不足崩溃

java - 运行 Spring WebApp 时代码状态 406

java - J老板 : WAR file in EAR can't find JAR library on classpath

hadoop - Mapreduce为什么即使对于很小的文件,拆分(文本文件)的数量也大于1

hadoop - Pig生成 key 更改列-比较先前记录与当前记录,但列不同

java - 如何让 IntelliJ 使用 Java7 作为 Google App Engine 开发服务器?

java - SimpleMappingExceptionResolver 中的 Spring doResolveException 未被调用

java - Mapreduce作业在群集上提供空输出

mongodb - 在 mongodb 中检索数组中的位置

java - 多输出路径(Java - Hadoop - MapReduce)