案例:执行wordcount,若输出目录存在则报错,可先判断目录存在,则删除:
public static void main(String[] args){
args = new String[]{
"/user/kfk/data/wc",
"/user/kfk/data/output"
};
WordCountMR wordCountMR = new WordCountMR();
try {
Path fileOutPath = new Path(args[1]);
FileSystem fileSystem = FileSystem.get(new Configuration());
if (fileSystem.exists(fileOutPath)){
fileSystem.delete(fileOutPath,true);
}
int status = wordCountMR.run(args);
System.exit(status);
}catch (Exception e){
}
}