zoukankan      html  css  js  c++  java
  • hadoop java上传文件

    import java.io.BufferedInputStream;
    import java.io.FileInputStream;
    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;
    import org.apache.hadoop.util.Progressable;
    public class UploadFile {
    public static void main(String[] args) {
    try {
    String localSrc = "/usr/local/hadoop/NOTICE.txt";
    String dst = "hdfs://localhost:9000/user/NOTICE.txt";
    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), new Progressable() {
    public void progress() {
    System.out.print(".");
    }
    });
    
    IOUtils.copyBytes(in, out, 4096, true);
    
    System.out.println("success");
    
    } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    }
  • 相关阅读:
    CSS 选择器
    HTML lable和fieldset
    html image和表格
    HTML a标签
    html 提交后台的标签
    HTML INPUT系列使用
    HTML内标签、换行
    HTML 头部详解
    单例模式
    const 指针的三种使用方式
  • 原文地址:https://www.cnblogs.com/tk55/p/6441593.html
Copyright © 2011-2022 走看看