在mian函数里这样写
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
conf.setStrings("mapred.tasktracker.reduce.tasks.maximum", "4");
conf.setClass("mapred.map.output.compression.codec", GzipCodec.class, CompressionCodec.class);//代码实现map输出压缩减少网络传输压力
Job job = new Job(conf);
job.setJarByClass(fenxi.class);
job.setJobName("wordcount");
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
job.setNumReduceTasks(2);
job.setMapperClass(WordCountMap.class);
job.setReducerClass(WordCountReduce.class);
job.setInputFormatClass(TextInputFormat.class);
job.setOutputFormatClass(TextOutputFormat.class);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
FileOutputFormat.setCompressOutput(job,true);//代码实现输出压缩
FileOutputFormat.setOutputCompressorClass(job, GzipCodec.class);
job.waitForCompletion(true);
}
}
输出结果: