q w e t y u s hy d g h s g s e w f qw er a fs ds as
da ds sd df gf h g sds we sds sa fd sd sd as df f a w
we ew d fg s gf d h x f e f d sd r sd t ds
sd df f g x w t yu d c s t d d e
q w e t y u s hy d g h s g s e w f qw er a fs ds as
da ds sd df gf h g sds we sds sa fd sd sd as df f a w
we ew d fg s gf d h x f e f d sd r sd t ds
sd df f g x w t yu d c s t d d e
q w e t y u s hy d g h s g s e w f qw er a fs ds as
da ds sd df gf h g sds we sds sa fd sd sd as df f a w
we ew d fg s gf d h x f e f d sd r sd t ds
sd df f g x w t yu d c s t d d e
q w e t y u s hy d g h s g s e w f qw er a fs ds as
da ds sd df gf h g sds we sds sa fd sd sd as df f a w
we ew d fg s gf d h x f e f d sd r sd t ds
sd df f g x w t yu d c s t d d e
q w e t y u s hy d g h s g s e w f qw er a fs ds as
da ds sd df gf h g sds we sds sa fd sd sd as df f a w
we ew d fg s gf d h x f e f d sd r sd t ds
sd df f g x w t yu d c s t d d e
q w e t y u s hy d g h s g s e w f qw er a fs ds as
da ds sd df gf h g sds we sds sa fd sd sd as df f a w
we ew d fg s gf d h x f e f d sd r sd t ds
sd df f g x w t yu d c s t d d e
q w e t y u s hy d g h s g s e w f qw er a fs ds as
da ds sd df gf h g sds we sds sa fd sd sd as df f a w
we ew d fg s gf d h x f e f d sd r sd t ds
sd df f g x w t yu d c s t d d e
1.自定义Mapper
package com.wc;import org.apache.hadoop.io.IntWritable;import org.apache.hadoop.io.LongWritable;import org.apache.hadoop.io.Text;import org.apache.hadoop.mapreduce.Mapper;import java.io.IOException;import java.util.StringTokenizer;publicclassWordCountMapperextendsMapper<LongWritable, Text, Text, IntWritable>{private Text mapOutputKey =newText();private IntWritable mapOutputValue =newIntWritable();@Overrideprotectedvoidmap(LongWritable key, Text value, Context context)throws IOException, InterruptedException {//1.将读取的文件变成,偏移量+内容//读取一行数据
String linevalue = value.toString();//使用空格分隔
StringTokenizer st =newStringTokenizer(linevalue);//判断是否还有分隔符,有的话代表还有单词while(st.hasMoreTokens()){//返回从当前位置到下一个分隔符之间的字符串(单词)
String word = st.nextToken();
mapOutputKey.set(word);
mapOutputValue.set(1);
context.write(mapOutputKey, mapOutputValue);}}}
测试数据q w e t y u s hy d g h s g s e w f qw er a fs ds asda ds sd df gf h g sds we sds sa fd sd sd as df f a wwe ew d fg s gf d h x f e f d sd r sd t dssd df f g x w t yu d c s t d d eq w e t y u s...