Esta página aún no está disponible en su idioma local. Estamos trabajando arduamente para agregar más versiones de idiomas. Gracias por tu apoyo.

On this page

Appending File Content

Updated on 2022-09-14 GMT+08:00

Function Description

Append specific content to a specified file in HDFS. The process is as follows:

  1. Instantiate a FileSystem.
  2. Use the FileSystem instance to obtain various related resources.
  3. Add the content to the specified file in HDFS.
NOTE:

Close all requested resources after appending the file content.

Sample Code

The following provides code snippets. For complete codes, see the HdfsMain and HdfsWriter classes in com.huawei.bigdata.hdfs.examples.

 /**
 * Append file content.
 *
 * @throws IOException
 */
private void append() throws Exception {
     final String content = "I append this content.";
     InputStream in = (InputStream) new ByteArrayInputStream(
     content.getBytes());
   try {
     HdfsWriter writer = new HdfsWriter(fSystem, DEST_PATH
        + File.separator + FILE_NAME);
     writer.doAppend(in);
    System.out.println("success to append.");
    } finally {
// Stream resources must be closed.
    close(in);
    }
}
Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback