MAPREDUCE服务 MRS-追加信息到HDFS指定文件:代码样例

时间:2024-06-29 14:11:11

代码样例

如下是代码片段,详细代码请参考com.huawei.bigdata.hdfs.examples中的HdfsExample类。

/**
 * 追加文件内容
 *
 * @throws java.io.IOException
 */
private void append() throws IOException {
    final String content = "I append this content.";
    FSDataOutputStream out = null;
    try {
        out = fSystem.append(new Path(DEST_PATH + File.separator + FILE_NAME));
        out.write(content.getBytes());
        out.hsync();
         LOG .info("success to append.");
    } finally {
        // make sure the stream is closed finally.
        IOUtils.closeStream(out);
    }
}
support.huaweicloud.com/devg3-mrs/mrs_07_090016.html