file - 无法从 map 写入 hadoop 文件系统 (HDFS)

标签 file hadoop hdfs mapper

我正在尝试直接从 mapper 在 hadoop 文件系统中写入一个纯文本文件。

我是这样做的:

public void createFile(Configuration conf) throws IOException{    
    FileSystem fs = FileSystem.get(conf);

    Path filenamePath = new Path(conf.get("mapred.output.dir")+"/_"+conf.get("mapred.task.id"), "tree.txt");    

        try {

      if (fs.exists(filenamePath)) {        
        // remove the file first
        fs.delete(filenamePath);            
      }

      FSDataOutputStream out = fs.create(filenamePath);       
      out.writeUTF("hello, world!");        
      out.close();

    } catch (IOException ioe) {
        System.err.println("IOException during operation: " + ioe.toString());
        System.exit(1);
    }
}

并且它在伪分布式模式下不写任何东西。不过在单机写的很完美。

问题出在哪里?

最佳答案

我使用的是 Amazon Elastic MapReduce (EMR),我必须 get FileSystem by URI能够使用来自 S3 的文件。

FileSystem fs = FileSystem.get(uri, conf);

这可能对你没有帮助。

关于file - 无法从 map 写入 hadoop 文件系统 (HDFS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15374976/

相关文章:

c - C 程序停顿

JAVA 以 block 的形式读取文件,每个 block 为十六进制

Hadoop 映射器从 2 个不同的源输入文件中读取

hadoop - HDFS什么时候不可用?

hadoop - 如何使用webhdfs rest api复制文件并将其存储在另一个目录中?

c - 无法显示文件中数组的内容

java - 无法写入 FTP 服务器中存在的文本文件

hadoop - 方案 : hdfs 没有文件系统

rest - Apache Atlas 休息 API

sorting - Hadoop - 按键正确排序并按 reducer 分组