file path in hdfs

后端 未结 1 1912
被撕碎了的回忆
被撕碎了的回忆 2021-02-14 12:43

I want to read the file from the Hadoop File System.

In order to achieve the correct path of the file, I need host name and port address of the hdfs.

<
相关标签:
1条回答
  • 2021-02-14 13:14

    You can use either of the two ways to solve your error.

    1.

    String infile = "file.txt";
    Path ofile = new Path(infile);
    FileSystem fs = ofile.getFileSystem(getConf());
    

    2.

    Configuration conf = getConf();
    System.out.println("fs.default.name : - " + conf.get("fs.default.name"));
    // It prints uri  as : hdfs://10.214.15.165:9000 or something
    String uri = conf.get("fs.default.name");
    FileSystem fs = FileSystem.get(uri,getConf());
    
    0 讨论(0)
提交回复
热议问题