无法从映射器 Hadoop 打开 HDFS 文件

发布于 2025-01-02 22:41:51 字数 381 浏览 0 评论 0原文

我进行了很多搜索,但未能找到解决这个问题的方法。 实际上我想要访问的文件位于 HDFS 中,但不在输入路径(输入到 Map/Reduce 作业的路径)中。我想从映射器访问它。 输入路径中指定的 hdfs 路径可以从映射器完全访问,但其他 hdfs 文件则不能。

内部映射器:-

FileSystem FS1=FileSystem.get(conf);
Path path=new Path(""+FS1.getHomeDirectory());
FSDataInputStream fsdis=FS1.open(path);

导致以下错误: java.io.IOException:无法打开文件名/user/hadoop

提前致谢, 残酷的

I searched a lot but failed to find a solution to this problem.
Actually the file I want to access is in HDFS, but not in input path (the path which was input to the map/reduce job). And I want to access it from mapper.
The hdfs path specified in the input path is perfectly accessible from mapper but the other hdfs files are not.

INside mapper:-

FileSystem FS1=FileSystem.get(conf);
Path path=new Path(""+FS1.getHomeDirectory());
FSDataInputStream fsdis=FS1.open(path);

RESULTS IN the following ERROR:
java.io.IOException : Cannot open filename /user/hadoop

Thanks in advance,
Harsh

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

む无字情书 2025-01-09 22:41:51

我记得使用本教程来获得类似的工作。你可以尝试一下,它与你所写的内容只有一些区别,但仍然可能有帮助...

@Edit:啊,我刚刚注意到(在阅读评论后)你正在尝试打开 FS1.getHomeDirectory() 这是一个目录。我认为您应该指出文件而不是目录(您可以在“从文件读取数据”下的链接教程中查看它)。

I remember using this tutorial to get something similar working. You can give it a try, it has only a few difference tho what you've written but still it might help...

@Edit: ah and I just noticed (after reading the comments) that you are trying to open FS1.getHomeDirectory() and that is a directory. You should point out to a file not a directory, I think (you can check it out in the linked tutorial under "Reading data from a file").

世态炎凉 2025-01-09 22:41:51

你可以尝试一次吗

try {
    FileSystem fs = FileSystem.get (new Configuration ());
    FileStatus[] status = fs.listStatus (new Path ("hdfs://jp.seka.com:9000/user/jeka/in"));
    for (int i=0;i < status.length;i++) {
       BufferedReader br = new BufferedReader (new InputStreamReader (fs.open (status[i].getPath())));
       String line;
       line = br.readLine();
       while (line != null) {
           System.out.println (line);
           line=br.readLine ();
       }
    }
} catch (Exception e) {
      System.out.println("File not found");
}

can u try this once

try {
    FileSystem fs = FileSystem.get (new Configuration ());
    FileStatus[] status = fs.listStatus (new Path ("hdfs://jp.seka.com:9000/user/jeka/in"));
    for (int i=0;i < status.length;i++) {
       BufferedReader br = new BufferedReader (new InputStreamReader (fs.open (status[i].getPath())));
       String line;
       line = br.readLine();
       while (line != null) {
           System.out.println (line);
           line=br.readLine ();
       }
    }
} catch (Exception e) {
      System.out.println("File not found");
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文