您的位置:首页 > 移动开发

向HDFS文件append新内容

2012-11-07 16:56 375 查看
向hdfs文件增加内容,常见的是把小文件合并成为大文件和在文件末尾新增记录。

在hdfs文件末尾新增字符串内容:

FileSystem hdfs = FileSystem.get(conf);
FSDataOutputStream out;
if(!hdfs.exists(fpath))out = hdfs.create(fpath);
else out = hdfs.append(fpath);
out.writeChars(context.getBytes());  //context为新增内容
out.close();
hdfs.close();


需要在hdfs-site.xml中增加如下设置:

<property>
<name>dfs.support.append</name>
<value>true</value>
</property>
否则将会报错:

java.io.IOException: Append to hdfs not supported. Please refer to dfs.support.append configuration parameter.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: