再次运行程序,如果不删除上一次运行结束后的输出文件夹,就报错,每次手动去删除输出文件夹简直太麻烦了。在run()方法或者main()方法(视个人程序结构而定)中加入如下代码就可以让程序在运行时先自动删除与设定的输出文件夹同名的文件夹。
代码如下:
Path in = new Path(args1[0]);
Path out = new Path(args1[1]);
FileSystem fileSystem = FileSystem.get(new URI(in.toString()), new Configuration());
if (fileSystem.exists(out)) {
fileSystem.delete(out, true);
}