当第二次运行Jar程序时,出现Output文件已存在的Exception:
Exception in thread "main" org.apache.hadoop.mapred.FileAlreadyExistsException: Output directory hdfs://localhost:9000/user/gavin/output already exists at org.apache.hadoop.mapred.FileOutputFormat.checkOutputSpecs(FileOutputFormat.java:125) at org.apache.hadoop.mapreduce.JobSubmitter.checkSpecs(JobSubmitter.java:375) at org.apache.hadoop.mapreduce.JobSubmitter.submitJobInternal(JobSubmitter.java:334) at org.apache.hadoop.mapreduce.Job.submit(Job.java:960) at org.apache.hadoop.mapred.JobClient.submitJob(JobClient.java:534) at org.apache.hadoop.mapred.JobClient.runJob(JobClient.java:779) at WordCount.main(WordCount.java:53) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.hadoop.util.RunJar.ma
解决方法:
删除output目录即可:
进入bin目录,执行命令:hadoop fs -rmr output
然后再执行Jar运行命令,即可正常运行。
这也提示我们,在连续几次运行时,应该先删除生成的OUtput目录,然后再进行第二次的执行,或者将输出文件output改名。