code: public static void writeStringToFile(String path, String toWrite, SparkContext sc) throws IOException {
          FileSystem fileSystem = FileSystem.get(sc.hadoopConfiguration());
          try (BufferedOutputStream bos = new BufferedOutputStream(fileSystem.create(new Path(path)))) {
              bos.write(toWrite.getBytes("UTF-8"));
          }
      }
docs: Write a String to a file (on HDFS or local) in UTF-8 format
  
  @param path    Path to write to
  @param toWrite String to write
  @param sc      Spark context