如何在MapReduce程序中将文件附加到HDFS上

时间:2018-05-28 17:35:46

标签: java hadoop hdfs

我正在使用CDH-5.14.2-1.cdh5.14.2.p0.3。我试图将一些String附加到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_filetmp_file是一个空白文件)。我使用tmp_file创建了fs.create(path)另一种方法,因此创建了tmp_file但附加功能并不顺利。

我看了一些帖子,我意识到属性dfs.support.append必须是true。所以我搜索了Cloudera经理,但我找不到。相反,我写了conf.set("dfs.support.append", "true"),但它毫无意义。

我使用IOUtils.copyBytes(in, out, 4096, true)out.writeBytes(String tmp),但没有写任何内容。

我搜索并找到以下设置: setting

我设置了这个图,Deplor Client Configuration并重启所有服务。但没有改变......

我错了吗?

0 个答案:

没有答案