【问题标题】:"Wrong FS... expected: file:///" when trying to read file from HDFS in Java尝试从 Java 中的 HDFS 读取文件时出现“错误的 FS ... 预期:file:///”
【发布时间】:2020-04-13 01:56:10
【问题描述】:

我无法使用 Java 从 HDFS 读取文件:

String hdfsUrl = "hdfs://<ip>:<port>";
Configuration configuration = new Configuration();
configuration.set("fs.defaultFS", hdfsUrl);
FileSystem fs = FileSystem.get(configuration);
Path filePath = new Path(hdfsUrl + "/projects/harmonizome/data/achilles/attribute_list_entries.txt.gz");
FSDataInputStream fsDataInputStream = fs.open(filePath);

SEVERE: Servlet.service() for servlet [edu.mssm.pharm.maayanlab.Harmonizome.api.DownloadAPI] in context with path [/Harmonizome] threw exception
java.lang.IllegalArgumentException: Wrong FS: hdfs://146.203.54.165:8020/projects/harmonizome/data/achilles/attribute_list_entries.txt.gz, expected: file:///
    at org.apache.hadoop.fs.FileSystem.checkPath(FileSystem.java:310)
    at org.apache.hadoop.fs.RawLocalFileSystem.pathToFile(RawLocalFileSystem.java:47)
    at org.apache.hadoop.fs.RawLocalFileSystem.getFileStatus(RawLocalFileSystem.java:357)
    at org.apache.hadoop.fs.FilterFileSystem.getFileStatus(FilterFileSystem.java:245)
    at org.apache.hadoop.fs.ChecksumFileSystem$ChecksumFSInputChecker.<init>(ChecksumFileSystem.java:125)
    at org.apache.hadoop.fs.ChecksumFileSystem.open(ChecksumFileSystem.java:283)
    at org.apache.hadoop.fs.FileSystem.open(FileSystem.java:356)
    at edu.mssm.pharm.maayanlab.Harmonizome.api.DownloadAPI.readLines(DownloadAPI.java:37)
    at edu.mssm.pharm.maayanlab.Harmonizome.api.DownloadAPI.doGet(DownloadAPI.java:27)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
...

我没有设置我们的 HDFS,所以我不知道我不知道什么。任何帮助表示赞赏。

【问题讨论】:

    标签: java hadoop hdfs


    【解决方案1】:

    试试这个:

    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));
    

    请参考http://techidiocy.com/java-lang-illegalargumentexception-wrong-fs-expected-file/

    解决了一个类似的问题。

    【讨论】:

    • 虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接的答案可能会失效。
    • 我同意@scoa。我能够使用此链接解决我的问题,并使用工作代码编辑了您的答案。
    • @scoa 感谢您的建议。以后我会关注这个。
    • 我不明白。根本原因是什么?
    • 现在链接失效了,我也不知道根本原因了?
    【解决方案2】:

    下面的配置也可以工作!

    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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-07-09
      • 2021-11-05
      • 1970-01-01
      • 1970-01-01
      • 2017-01-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多