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

时间:2025-01-26 10:41:34

代码样例

如下是写文件的代码片段,详细代码请参考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/devg-lts-mrs/mrs_07_300014.html