我們隨便百度一個經典的MapReduce程序----wordcount的時候,在設置job文件輸入路徑和輸出路徑參數時,會看到別的博主會這麼寫:
Configuration conf = new Configuration();
Job wordCountJob = Job.getInstance(conf);
//省略。。。。
FileInputFormat.setInputPaths(wordCountJob,"hdfs://192.168.77.70:9000/wordcount/srcdata/");
FileOutputFormat.setOutputPath(wordCountJob, new Path("hdfs://192.168.77.70:9000/wordcount/output/"));
但是我在Idea裏面複製粘貼編譯時,其實是報錯的。這是因爲,它在版本中要求FileInputFormat調用的方法名是addInputPath且第一個參數是JobConf型,同樣FileOutputFormat調用的輸出名是setOutputPath,參數也是JobConf型。所以這個時候要進行強轉,具體做法如下:
FileInputFormat.addInputPath((JobConf)wordCountJob.getConfiguration(),new Path(args[0]));
FileOutputFormat.setOutputPath((JobConf)wordCountJob.getConfiguration(),new Path(args[1]));