我正在尝试直接从 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/