java—如何在mapreduce程序中在hdfs上追加文件

2lpgd968  于 2021-05-29  发布在  Hadoop
关注(0)|答案(0)|浏览(241)

我在用 CDH-5.14.2-1.cdh5.14.2.p0.3 . 我试图在hdfs上的现有文件中添加一些字符串。
然后我写道:

FileSystem fs = FileSystem.get(conf);
String str = "testtest";
FSDataOutputStream out = fs.append(new Path("tmp/tmp_file"));
InputStream in = new ByteArrayInputStream(str.getBytes("utf-8"));
byte[] b = new byte[1024];
int numBytes = 0;
while ((numBytes = in.read(b)) > 0) {
   out.write(b, 0, numBytes);
}

没有错误,但没有写入任何内容 tmp_file ( tmp_file 是一个空白文件)。我创造 tmp_file 另一种方法是 fs.create(path) ,所以 tmp_file 已创建,但append运行不正常。
我看过一些帖子,我意识到 dfs.support.append 必须是 true . 所以我搜索了cloudera manager,但找不到。相反,我写了 conf.set("dfs.support.append", "true") ,但毫无意义。
我曾经 IOUtils.copyBytes(in, out, 4096, true) 以及 out.writeBytes(String tmp) 但什么也没写。
我搜索并找到以下设置:

我像这个无花果 Deplor Client Configuration 并重新启动所有服务。但一切都没变…
我弄错了吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题