gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 06:25:24 26 4
gpt4 key购买 nike

有人知道如何在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com