title: Append data to existing file in HDFS Java
body: <p>I'm having trouble to append data to an existing file in HDFS. I want that if the file exists then append a line, if not, create a new file with the name given.</p>
  
  <p>Here's my method to write into HDFS.</p>
  
  <pre><code>if (!file.exists(path)){
     file.createNewFile(path);
  }
  
  FSDataOutputStream fileOutputStream = file.append(path); 
  BufferedWriter br = new BufferedWriter(new OutputStreamWriter(fileOutputStream));
  br.append("Content: " + content + "\n");
  br.close();
  </code></pre>
  
  <p>Actually this method writes into HDFS and create a file but as I mention is not appending.</p>
  
  <p>This is how I test my method:</p>
  
  <pre><code>RunTimeCalculationHdfsWrite.hdfsWriteFile("RunTimeParserLoaderMapperTest2", "Error message test 2.2", context, null);
  </code></pre>
  
  <p>The first param is the name of the file, the second the message and the other two params are not important.</p>
  
  <p>So anyone have an idea what I'm missing or doing wrong?</p>