HDFSAPI

HDFS文件上传

  1. Java代码
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    public void putFileToHDFS() throws URISyntaxException, IOException, InterruptedException {

    //1、创建配置信息对象

    Configuration conf = new Configuration();//hjhj

    //2、设置部分参数
    conf.set("dfs.replication","2");

    //3、找到HDFS地址
    //final URI uri, final Configuration conf, String user
    FileSystem fs = FileSystem.get(new URI("hdfs://vmaster:9000"), conf, "root");

    //4、上传本地文件路径
    Path src = new Path("F:\\Course\\aliyun\\transaction_details.csv");

    //5、要上传的HDFS的路径
    Path dest = new Path("hdfs://vmaster:9000/");

    //6、以拷贝的方式上传,从src -> dest
    fs.copyFromLocalFile(src,dest);

    //7、关闭
    fs.close();

    //
    System.out.println("OK了");
    }
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×