• 将本地文件复制到hadoop文件系统


    package com.yoyosys.cebbank.bdap.service.mr;
    
    import java.io.BufferedInputStream;
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.net.URI;
    
    import org.apache.hadoop.conf.Configuration;
    import org.apache.hadoop.fs.FileSystem;
    import org.apache.hadoop.fs.Path;
    import org.apache.hadoop.io.IOUtils;
    
    /**
     * 将本地文件复制到hadoop文件系统
     * @author Administrator
     *
     */
    
    public class FileSystemCat {
        public static void main(String[] args) throws IOException {
            String localsrc = args[0];
            String dst = args[1];
            InputStream in = new BufferedInputStream(new FileInputStream(localsrc));
            Configuration conf = new Configuration();
            FileSystem fs = FileSystem.get(URI.create(dst),conf);
            OutputStream out = fs.create(new Path(dst));
            IOUtils.copyBytes(in, out,4096, true);//true代表是否执行完关闭数据流
        }
    
    }

    package com.yoyosys.cebbank.bdap.service.mr;
    import java.io.BufferedInputStream;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.net.URI;
    import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.fs.FileSystem;import org.apache.hadoop.fs.Path;import org.apache.hadoop.io.IOUtils;
    /** * 将本地文件复制到hadoop文件系统 * @author Administrator * */
    public class FileSystemCat {public static void main(String[] args) throws IOException {String localsrc = args[0];String dst = args[1];InputStream in = new BufferedInputStream(new FileInputStream(localsrc));Configuration conf = new Configuration();FileSystem fs = FileSystem.get(URI.create(dst),conf);OutputStream out = fs.create(new Path(dst));IOUtils.copyBytes(in, out,4096, true);//true代表是否执行完关闭数据流}
    }

  • 相关阅读:
    Java Formatter 阅读心得
    Android 应用的动画实践View Animation篇
    Hexo 简明入门教程(一)
    用Gradle 构建你的android程序依赖管理篇
    MQTT 折腾笔记协议简读
    ingress 在中国大众篇
    谈谈常见的移动应用设计风格
    用nodejs 改造一个移动版本的网站
    Android AdapterView 源码分析以及其相关回收机制的分析
    关于计算机类课程实验教学的思考
  • 原文地址:https://www.cnblogs.com/zhangtongzct/p/6094223.html
Copyright © 2020-2023  润新知