idea默认的编码是UTF-8,所以在输入的文件编码不是UTF-8时,就有可能会出现乱码的情况。
方法一:
在map或者reduce阶段在封装前将Text修改一下
String s = new String(value.getBytes(),0,value.getLength(),"GBK");
方法二:
在写出流的方法public void write(Text text, IntWritable intWritable) throws IOException, InterruptedException 中将String s = text.toString();改成
String s = new String(text.getBytes(),0,text.getLength(),"UTF-8");
方法三:chongfudata.writeBytes(s+"\n");
改成chongfudata.write(s.getBytes());写出输出到文件中