copying directory from local system to hdfs java code

后端 未结 2 698
后悔当初
后悔当初 2020-12-16 01:58

I\'m having a problem trying to copy a directory from my local system to HDFS using java code. I\'m able to move individual files but can\'t figure out a way to move an enti

2条回答
  •  既然无缘
    2020-12-16 02:21

    Just use the FileSystem's copyFromLocalFile method. If the source Path is a local directory it will be copied to the HDFS destination:

    ...
    Configuration conf = new Configuration();
    conf.addResource(new Path("/home/user/hadoop/conf/core-site.xml"));
    conf.addResource(new Path("/home/user/hadoop/conf/hdfs-site.xml"));
    
    FileSystem fs = FileSystem.get(conf);
    fs.copyFromLocalFile(new Path("/home/user/directory/"), 
      new Path("/user/hadoop/dir"));
    ...   
    

提交回复
热议问题