Upload data to HDFS with Java API

前端 未结 3 1929
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-24 19:19

I\'ve searched for some time now and none of the solutions seem to work for me.

Pretty straightforward - I want to upload data from my local file system to HDFS using th

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-24 19:55

    i am not sure about the approach you are following, but below is one way data can be uploaded to hdfs using java libs :

    //imports required 
    import org.apache.hadoop.conf.Configuration;
    import org.apache.hadoop.fs.FileSystem;
    
    //some class here .....
    Configuration conf = new Configuration();
    conf.set("fs.defaultFS", );
    FileSystem fs = FileSystem.get(conf);
    fs.copyFromLocalFile(, );
    

    Also if you have hadoop conf xmls locally, you can include them in you class path. Then hadoop fs details will automatically be picked up at runtime, and you will not need to set "fs.defaultFS" . Also if you are running in old hdfs version you might need to use "fs.default.name" instead of "fs.defaultFS". If you are not sure of the hdfs endpoint, it is usually the hdfs namenode url . Here is example from previous similar question copying directory from local system to hdfs java code

提交回复
热议问题