MAPREDUCE服务 MRS-创建HDFS文件并写入内容:代码样例

时间:2024-06-29 14:10:57

代码样例

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

/**
 * 创建文件,写文件
 *
 * @throws java.io.IOException
 * @throws com.huawei.bigdata.hdfs.examples.ParameterException
 */
private void write() throws IOException {
   final String content = "hi, I am bigdata. It is successful if you can see me.";
   FSDataOutputStream out = null;
   try {
       out = fSystem.create(new Path(DEST_PATH + File.separator + FILE_NAME));
       out.write(content.getBytes());
       out.hsync();
        LOG .info("success to write.");
   } finally {
    // make sure the stream is closed finally.
    IOUtils.closeStream(out);
  }
}
support.huaweicloud.com/devg3-mrs/mrs_07_090015.html