Amazing technological breakthrough possible @S-Logix

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • +91- 81240 01111

Social List

How to append data into file in HDFS?


Data into the HDFS is written using the FileSystem and OutputStreamWriter Object available in hadoop.fs and package that writes the data as string.FSDataOutputStream and FileSystem objects are used to append the data into the existing file.

Sample Code

import java.util.*;

import org.apache.hadoop.fs.*;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.mapred.*;
import org.apache.hadoop.util.*;

public class appendData {

public static void main(String[] args) throws Exception {

try {

Configuration conf = new Configuration();

Path path = new Path(“hdfs://localhost:54310/home/WriteData”);

FileSystem hdfs = path.getFileSystem(conf);

BufferedReader bfr = new BufferedReader(new InputStreamReader(; //open file first

String str = null;

BufferedWriter br = new BufferedWriter(new OutputStreamWriter(hdfs.create(path, true)));

while ((str = bfr.readLine()) != null) {

br.write(str); // write file content




br.write(“Append Data to HDFS”); // append into file


br.close(); // close it

} catch (Exception e) {

System.out.println(“File not found”);





Append data into file in HDFS