自定义类中重写write和readFields方法
@Override
public void write(DataOutput out) throws IOException {
out.writeUTF(this.name);
out.writeUTF(this.course);
}
@Override
public void readFields(DataInput in) throws IOException {
this.name = in.readUTF();
this.course = in.readUTF();
}
map方法中设置中文属性值
@Override
protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
String[] split = value.toString().split("\t");
if (split.length == 6) {
k.setName(split[0]);
k.setCourse("语文");
v.set(Double.parseDouble(split[3].trim()));
context.write(k, v);
k.setCourse("数学");
v.set(Double.parseDouble(split[4].trim()));
context.write(k, v);
k.setCourse("英语");