java - 如何在 MapReduce 程序中将文件附加到 HDFS
问题描述
我正在使用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
通过 using 创建了另一种方法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
然后重新启动所有服务。但什么都没有改变……</p>
我弄错了吗?
解决方案
推荐阅读
- html - 如何使用 Bootstrap v5.1 在剩余可用空间的中心对齐 DIV 元素
- postman - Postman / Newman 并从 Azure Blob 上传文件而不是本地文件
- docker - docker 引擎创建的 iptables 规则
- rust - 如何使用父成员的方法获取工作区成员的版本?
- python - 整个数据帧的最大索引?
- json - 如何在laravel中使用json键名对结果进行分组
- python - python:将文本文件转换为csv文件
- java - 如何使用球衣客户端模拟与发布请求一起发送的多值地图?
- javascript - req.headers('Authorization') 未定义
- node.js - 如何在文档中查找包含数组中所有元素的文档?