39. Word Countfoo.txt: Sweet, this is the foo file
bar.txt: This is the bar file
期望输出:
sweet 1
this 2
is 2
…
40. Word Count public static class TokenizerMapper
extends Mapper
41. Word Count public static class IntSumReducer
extends Reducer {
private IntWritable result = new IntWritable();
public void reduce(Text key, Iterable values,
Context context
) throws IOException, InterruptedException {
int sum = 0;
for (IntWritable val : values) {
sum += val.get();
}
result.set(sum);
context.write(key, result);
}
}