MapReduce 判断输出路径是否存在问题
来源:互联网 发布:东方财富网龙虎榜数据 编辑:程序博客网 时间:2024/04/30 20:20
写MapReduce程序时,最后加一个判断当前输出路径是否存在的代码,如果输出路径存在则删除。这样可以避免出现如下错误:
Output directory hdfs://192.168.42.130:9000/output already exists
具体代码如下:
final static String OUTPUT_PATH = "hdfs://192.168.42.130:9000/output"; //输出路径用字符串表示,在主类中定义,或者由主方法参数给出Path path = new Path(OUTPUT_PATH); FileSystem fileSystem = path.getFileSystem(conf); //getFileSystem()函数功能 Return the FileSystem that owns this Path. if (fileSystem.exists(new Path(OUTPUT_PATH))) { fileSystem.delete(new Path(OUTPUT_PATH),true);}
在FileSystem 类下的delete()函数源码如下:
public boolean delete(Path f) throws IOException { return delete(f, true); } /** Delete a file. * * @param f the path to delete. * @param recursive if path is a directory and set to * true, the directory is deleted else throws an exception. In * case of a file the recursive can be set to either true or false. * @return true if delete is successful else false. * @throws IOException */ public abstract boolean delete(Path f, boolean recursive) throws IOException;
函数由两个参数,第一个为要删除文件的路径(类型Path),第二个函数为是否递归删除文件夹及其字目录(类型boolean),一般为true。删除失败抛出IOException异常。
阅读全文
0 0
- MapReduce 判断输出路径是否存在问题
- 判断文件路径是否存在
- 判断某个路径是否存在
- 判断某个路径是否存在
- 判断一个路径是否存在
- linux下判断路径是否存在(文件夹是否存在)
- linux下判断路径是否存在(文件夹是否存在)
- linux下判断路径是否存在(文件夹是否存在)
- linux下判断路径是否存在(文件夹是否存在)
- 判断路径是否存在,文件拷贝
- java判断指定路径文件是否存在
- PHP判断远程路径是否存在
- 判断指定路径下文件是否存在
- 判断路径文件夹是否存在,不存在创建
- C# 判断 文件路径/文件 是否存在
- spark 判断s3路径是否存在
- C++判断当前路径是否存在
- python中如何判断路径是否存在
- 解决安卓与IOS点击效果兼容(去除移动端Ios点击阴影 )
- springMVC集成swagger
- 3D Convolutional Neural Networks for Human Action Recognition
- JAVA获得版本号以及字节码编译版本
- springboot配置
- MapReduce 判断输出路径是否存在问题
- C++ initializer_list(列表初始化)
- 回调函数批本质,求资深专家反驳!!!
- Ubuntu恢复普通用户权限<1000:1000改为0:0>后只能guest身份进入系统(亲测有效)
- Android用CameraApi实现相机开发以及用opengl es实现相机实时滤镜
- 关于hdfs中启动namenode进程
- pandas.DataFrame.describe
- spring映射数据库的命名规则小总
- 主组织物料>物料目录>规格型号 无法更新解决方案