从代码上解决Output directory already exists错误,避免每次调试都要手动删除输出文件夹

// 判断output文件夹是否存在,如果存在则删除
    Path outPath = new Path("hdfs://192.168.9.13:8020/meanwhileFind");// 输出路径
    FileSystem fs = outPath.getFileSystem(conf);// 根据输出路径找到文件,参数为配置文件
    if (fs.exists(outPath)) {
        fs.delete(outPath);
        // fs.delete(outPath, true);true的意思是,就算output有东西,也一带删除,默认为true

    }
    FileInputFormat.setInputPaths(job, new Path("hdfs://192.168.9.13:8020/gradeMarking"));
    FileOutputFormat.setOutputPath(job, outPath);

 

posted @ 2017-11-05 21:44  TheCompass  阅读(2722)  评论(0编辑  收藏  举报