“Wrong FS… expected: file:///” when trying to read file from HDFS in Java

前端 未结 2 1478
情话喂你
情话喂你 2021-01-18 00:55

I am unable to read a file from HDFS using Java:

String hdfsUrl = \"hdfs://:\";
Configuration configuration = new Configuration();
conf         


        
相关标签:
2条回答
  • 2021-01-18 01:08

    Try this:

    Configuration configuration = new Configuration();
    FileSystem fs = FileSystem.get(new URI(<url:port>), configuration);
    Path filePath = new Path(<path/to/file>);
    FSDataInputStream fsDataInputStream = fs.open(filePath);
    BufferedReader br = new BufferedReader(new InputStreamReader(fsDataInputStream));
    

    Please refer to http://techidiocy.com/java-lang-illegalargumentexception-wrong-fs-expected-file/

    A similar problem is addressed.

    0 讨论(0)
  • 2021-01-18 01:28

    Also below Configuration works!

    Configuration conf = new Configuration();
    conf.addResource(new Path("/usr/hdp/2.6.3.0-235/hadoop/etc/hadoop/core-site.xml"));
    FileSystem fs = FileSystem.get(conf);
    
    0 讨论(0)
提交回复
热议问题