public static void putStringToFile(final HdfsApi hdfs,final String filePath, final String content) throws HdfsApiException {

    try {
      synchronized (hdfs) {
        hdfs.execute(new PrivilegedExceptionAction<Void>() {
          @Override
          public Void run() throws Exception {
            final FSDataOutputStream stream = hdfs.create(filePath, true);
            stream.write(content.getBytes());
            stream.close();
            return null;
          }
        }, true);
      }
    } catch (IOException e) {
      throw new HdfsApiException("HDFS020 Could not write file " + filePath, e);
    } catch (InterruptedException e) {
      throw new HdfsApiException("HDFS021 Could not write file " + filePath, e);
    }
  }
Write string to file with overwriting
@param filePath path to file
@param content new content of file
contrib/views/utils/src/main/java/org/apache/ambari/view/utils/hdfs/HdfsUtil.java