工作前自动删除已有文件

This commit is contained in:
2018-04-18 21:35:35 +08:00
parent ea371115a7
commit 71fb47da05
2 changed files with 199 additions and 85 deletions

View File

@@ -1,6 +1,7 @@
package com.fjy.hadoop.mapreduce;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
@@ -87,6 +88,14 @@ public class WordCountApp {
//创建Configuration
Configuration configuration = new Configuration();
//清理已存在的输出目录
Path outputPath = new Path(args[1]);
FileSystem fileSystem = FileSystem.get(configuration);
if (fileSystem.exists(outputPath)){
fileSystem.delete(outputPath);
System.out.println("The exist files had been deleted!");
}
//创建作业
Job job = Job.getInstance(configuration, "wordcount");