> 文章列表 > scala 拷贝本地文件到hdfs

scala 拷贝本地文件到hdfs

scala 拷贝本地文件到hdfs

        import org.apache.hadoop.conf.Configurationimport org.apache.hadoop.fs.{FileSystem, Path}val conf = new Configuration()conf.set("fs.defaultFS","hdfs://172.13.130.2:8020")val fs = FileSystem.get(conf)// 本地文件路径和 HDFS 目标路径val localPath = new Path("D:\\\\SWAP\\\\1.txt")val hdfsPath = new Path("/yy/1.txt")// 上传本地文件到 HDFS 默认是覆盖模式// copyFromLocalFile(boolean delSrc, boolean overwrite, Path[] srcs, Path dst)
//        fs.copyFromLocalFile(localPath, hdfsPath) // 覆盖模式
//        fs.copyFromLocalFile(false,false,localPath, hdfsPath) // 报错 Target /yy/1.txt already exists
//        fs.copyFromLocalFile(false,true,localPath, hdfsPath) //文件替换
//        fs.copyFromLocalFile(true,true,localPath, hdfsPath) // 删除localPath中文件 替换hdfsPath中文件