Q:

Count number of character occurrences from input text file

How to convert flatMap of a text file to flatMap of characters?  I have to count of occurrences of each character from a text file.  What approach to take after following code?  
val words = readme.flatMap(line => line.split(" ")).collect()

A:

In order to convert each String into its representing characters, you need an additional flatMap:
val characters = lines.flatMap(_.split(" ")).flatMap(_.toCharArray)

scala> val lines = Array("hello world", "yay more lines")
lines: Array[String] = Array(hello world, yay more lines)

scala> lines.flatMap(_.split(" ")).flatMap(_.toCharArray)
res3: Array[Char] = Array(h, e, l, l, o, w, o, r, l, d, y, a, y, m, o, r, e, l, i, n, e, s)

Although this is a Scala console, it will work the same on an RDD.